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

Aberto
aberto por Archivist 4 dias atrás · 0 comentários

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 added the
enhancement
label 4 dias atrás
Archivist se auto atribuiu para esta issue 4 dias atrás
Acesse para participar desta conversação.
Sem marco
Sem responsável
1 participante(s)
Notificações
Data limite

Data limite não informada.

Dependências

Esta issue atualmente não tem dependências.

Carregando…
Ainda não há conteúdo.