Advertisement
WeltEnSTurm

Untitled

Mar 1st, 2017
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1. # version current
  2. # meh
  3.  
  4. fold = macro data a b:
  5.     accum = null
  6.     each v in $ get data:
  7.         if accum == null:
  8.             accum = v
  9.         else:
  10.             accum = call a accum b v
  11.     accum
  12.  
  13. # version a
  14. # excess parameters are treated as names to block,
  15. # no need to adress them in macro definition
  16. # inconsistent with 'each', e.g. each a b in sometable:
  17. # would have to move names to the end to become consistent e.g. each sometable a b:
  18.  
  19. fold = macro data cb:
  20.     accum = null
  21.     each v in data:
  22.         if accum == null:
  23.             accum = v
  24.         else:
  25.             accum = cb accum v
  26.     accum
  27.  
  28.  
  29. # version b
  30. # more control, uglier macro definition
  31.  
  32. fold = macro data a b cb:
  33.     accum = null
  34.     each v in (value data):
  35.         if accum == null:
  36.             accum = v
  37.         else:
  38.             # version b.0
  39.             (name a) = accum
  40.             (name b) = v
  41.             accum = cb
  42.             # version b.1
  43.             accum = cb (bind a accum) (bind b v)
  44.             # version b.2, would have to implement named parameters?
  45.             accum = cb (a)=accum (b)=v
  46.     accum
  47.  
  48. # version c
  49. # fake type system
  50.  
  51. fold = macro (value data) (name a) (name b) cb: # last parameter is always a block
  52.     # ...
  53.  
  54. # calling all of them
  55.  
  56. fold sometable a b:
  57.     a + b
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement