User Tools

Site Tools


lambdas_anonymous_functions

Differences

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

Link to this comparison view

lambdas_anonymous_functions [2022/03/19 13:43]
richardrussell created
lambdas_anonymous_functions [2022/03/19 20:44] (current)
richardrussell Changed to illustrate passing two parameters
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.txt ยท Last modified: 2022/03/19 20:44 by richardrussell