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

Abertas
aberta há 4 dias por Archivist · 0 comentários
Archivist comentado há 4 dias

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 adicionou a etiqueta
enhancement
há 4 dias
Archivist atribuiu a si mesmo(a) esta questão há 4 dias
Inicie a sessão para participar neste diálogo.
Sem etapa
Sem responsáveis
1 Participantes
Notificações
Date limite

Sem data limite definida.

Dependências

Esta questão não tem quaisquer dependências, neste momento.

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