Paste: (Fixed) Implementation of the <[ ... -- ... ]> thing

Author: Leo Mehraban
Mode: factor
Date: Mon, 10 Feb 2025 11:41:26
Plain Text |
! the first time I tried to submit this, I made a typo

<PRIVATE
ERROR: strange-item-in-supershuffle item ; ! calling it supershuffle for now because I can't think of a better name

: process-single-item ( vars item -- quot ) swap dupd index    
  [ 1quotation ] 
  [ dup quotation? [ strange-item-in-supershuffle ] unless ]   
  if ;

MACRO: call-restore ( quots -- quot ) 
   [ ] [ [ [ dip ] curry ] dip prepose ] reduce ;
PRIVATE>

SYNTAX: <[ 
   "--" parse-tokens 
   make-locals 
   [ \ ]> parse-until ] with-words 
   dupd [ process-single-item ] with map 
   [ call-restore ] curry <lambda> ?rewrite-closures concat append! ;

! i'll add tests for these when I turn this into a full vocabulary

! 1 2 3 <[ a b c -- b c a ]> ! outputs 2 3 1

! 1 2 3 <[ a b c -- b [ a c + ] a ]> ! outputs 2 4 1

! 10 9 1 5 7 <[ a b c -- [ b 10 * ] c [ + ] ]> outputs 50 7 19

New Annotation

Summary:
Author:
Mode:
Body: