• by hzhou321 on 5/5/2015, 11:02:10 PM

    Or, with a text based meta-layer (MyDef):

        import macros
    
        $(for:A in A,B,C)
            proc $(A)() = echo "$(A)"
    
        proc execute(order: seq[int], callbacks: seq[proc]) =  
          for i in items(order):                              
            callbacks[i]()
    
        execute(@[0,0,1,2,1,2], @[A, B, C])

  • by kazinator on 5/5/2015, 9:14:31 PM

    Way too cumbersome, sorry.

    TXR Lisp:

      @(do
        (macro-time
          (defun abc-proc (n)
            ^(defun ,n () (pprinl ',n))))
    
        (defmacro abc-procs (. n)
          ^(progn ,*[mapcar abc-proc n]))
    
        (abc-procs a b c)
    
        (defun exec (order callbacks)
          (each ((i order))
            [[callbacks i]]))
    
        (exec '(0 0 1 2 1 2) '(a b c)))
    
      $ txr test.txr
      a
      a
      b
      c
      b
      c
    
    Variation on exec:

      (defun exec (order callbacks)
        (mapdo (op [callbacks @1]) order))

  • by shasta on 5/5/2015, 9:22:53 PM

    I think the author should post a follow-up after he's tried to do substantial work with this style meta-programming. My guess is that you want to keep templated code to an absolute minimum.

  • by kbd on 5/5/2015, 8:09:59 PM

    It's a small thing, but I'm so glad they renamed it to "Nim". Its prior name carries such a negative connotation, while just shortening that gave a name that's cute and simple.