fork download
  1. # PicoLisp program that uses dynamic scoping to mirror the C example
  2.  
  3. # initialize globals
  4. (setq a 0 b 0 c 0 d 0)
  5.  
  6. # g1 takes two parameters (these are named differently here to make
  7. # the dynamic/global 'a' and 'd' bindings visible inside the body)
  8. (de g1 (bb cc)
  9. (prinl a bb cc d))
  10.  
  11. # g2 forwards its arguments to g1
  12. (de g2 (aa cc)
  13. (g1 aa cc))
  14.  
  15. # g3: local b = 3, call g1, then create a new block that binds c and d,
  16. # call g2, then call g1 again and return b
  17. (de g3 (cc aa)
  18. (let (b 3)
  19. (g1 aa b)
  20. (let (c 8 d 4)
  21. (g2 aa b))
  22. (g1 aa b)
  23. b))
  24.  
  25. # main: local a=4, b=5; a = g3(b,c); g3(b,a)
  26. (de main ()
  27. (let (a 4 b 5)
  28. (setq a (g3 b c))
  29. (g3 b a)))
  30.  
  31. # run main
  32. (main)
  33.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
4030
4034
4030
3330
3334
3330