Other languages
Computer Science
Meta
Quotations are the general term for anonymous functions or lambdas. They denote a snippet of code which can be executed later. Their exact syntax varies by language. For example, Factor denotes quotations using square-brackets. Whereas, Tal and Postscript denote them using curly-brackets. Regardless of syntax, they are core to constructing higher-order functions in concatenative languages.
A higher-order function is an operation that utilize other functions as inputs or create new functions as outputs. This feature is leverage by a core utility of concatenative programming: combinators. They enable a programmer to name code not values.
! { 1 4 9 16 } { 1 2 3 4 } [ sq ] map
// [10, 20, 30] [1, 2, 3] { (* 10) } map
(02 04 06 08 0a) { 01 02 03 04 05 } STH2r { STH2k LDAk DUP ADD STH2r STA JMP2r } STH2r foreach
Implementation of foreach
:
@foreach ( {bytes}* fn* -- bytes* ) ,&t STR2 DUP2k #0002 SUB2 LDA2 ADD2 SWP2 &l ( -- ) [ LIT2 &t $2 ] JSR2 INC2 GTH2k ?&l POP2 POP2 JMP2r
This revision created on Wed, 6 Sep 2023 05:00:29 by CapitalEx (Expand anonymous functions into a more general page about quotations and higher-order functions)