User Tools

Site Tools


lambdas_anonymous_functions

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
lambdas_anonymous_functions [2022/03/19 13:43] – created richardrusselllambdas_anonymous_functions [2024/01/05 00:22] (current) – external edit 127.0.0.1
Line 2: Line 2:
 //by Richard Russell, March 2022// //by Richard Russell, March 2022//
  
-BBC BASIC does not 'officially' support lambdas (anonymous functions), in the sense that the language itself does not incorporate that concept, but as is so often the case the functionality can quite easily be synthesised from lower-level operations.+BBC BASIC does not 'officially' support lambdas (anonymous functions), in that the language itself does not incorporate that concept.  But as is so often the case the functionality can quite easily be synthesised from lower-level operations.
  
 Here is an example (it relies on extensions available in //BBC BASIC for Windows//, //BBC BASIC for SDL 2.0// and the //Console Mode editions//): Here is an example (it relies on extensions available in //BBC BASIC for Windows//, //BBC BASIC for SDL 2.0// and the //Console Mode editions//):
Line 8: Line 8:
 <code bb4w> <code bb4w>
       PROC_lambda(foo{}, "(x) = x * x")       PROC_lambda(foo{}, "(x) = x * x")
-      PROC_lambda(bar{}, "(x) PRINT x ^ : ENDPROC")+      PROC_lambda(bar{}, "(x, y) PRINT x ^ : ENDPROC")
       PRINT FN(foo{})(5)       PRINT FN(foo{})(5)
-      PROC(bar{})(PI)+      PROC(bar{})(PI, 2)
       END       END
  
lambdas_anonymous_functions.1647697392.txt.gz · Last modified: 2024/01/05 00:17 (external edit)