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

Öppen
öppnade 4 dagar sedan av Archivist · 0 kommentarer
Archivist kommenterad 4 dagar sedan

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 lade till etiketten
enhancement
4 dagar sedan
Archivist tilldelade denna till sig själv 4 dagar sedan
Logga in för att delta i denna konversation.
Ingen Milsten
Ingen tilldelad
1 Deltagare
Notiser
Förfallodatum

Inget förfallodatum satt.

Beroenden

Det här ärendet har för närvarande inga beroenden.

Laddar…
Det finns inget innehåll än.