#3 Quoting functions to inject function references in macros or other operations

Open
opened 4 dagen geleden by Archivist · 0 comments

The goal would be to be able to insert a word-ref or native-word-ref type that would decay into a word or native-word upon either an unquoting operation or being read in a native function. This would open the way to have array.map and other powerful high order functions, as well as allow macros to contain executable code (for example, by making them selectively unquote elements) allowing some better creative prospects.

Syntax

'token creates a function reference to the applicable token that will be pushed to the stack.

fn.unquote extracts, pops, then runs the function that is on top of the stack (schedules it instead of the current function with before now as its new index).

# array
# fn-ref array 
fn array.foreach do
    dup array.size 0
    # fn-ref array end it
    2 pluck 2 pluck == end_loop jump_if
    # fn-ref array end it
    loop:
        dup 4 pluck
        # fn-ref array end it it array
        array.index 
        # fn-ref array end it elem
        5 pluck fn.unquote
        # fn-ref array end it
        1 +
   2 pluck 2 pluck > loop jump_if
   end_loop: drop drop drop drop
end
[ 1 2 3 ] 'print_int swap array.foreach
expected output:
1 2 3
The goal would be to be able to insert a `word-ref` or `native-word-ref` type that would decay into a `word` or `native-word` upon either an unquoting operation or being read in a native function. This would open the way to have `array.map` and other powerful high order functions, as well as allow macros to contain executable code (for example, by making them selectively unquote elements) allowing some better creative prospects. ## Syntax `'token` creates a function reference to the applicable token that will be pushed to the stack. `fn.unquote` extracts, pops, then runs the function that is on top of the stack (schedules it instead of the current function with before now as its new index). ``` # array # fn-ref array fn array.foreach do dup array.size 0 # fn-ref array end it 2 pluck 2 pluck == end_loop jump_if # fn-ref array end it loop: dup 4 pluck # fn-ref array end it it array array.index # fn-ref array end it elem 5 pluck fn.unquote # fn-ref array end it 1 + 2 pluck 2 pluck > loop jump_if end_loop: drop drop drop drop end ``` ``` [ 1 2 3 ] 'print_int swap array.foreach ``` ###### expected output: ``` 1 2 3 ```
Archivist voegde het
enhancement
label 4 dagen geleden toe
Archivist heeft dit 4 dagen geleden aan zichzelf toegewezen
Log in om deel te nemen aan deze discussie.
Geen mijlpaal
Niet toegewezen
1 deelnemers
Notificaties
Vervaldatum

Geen vervaldatum ingesteld.

Afhankelijkheden

Deze kwestie heeft momenteel geen afhankelijkheden.

Laden…
Er is nog geen inhoud.