Hacker News new | ask | show | jobs
by kazinator 4061 days ago
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))
2 comments

You can do it a bit shorter and easier in Nim as well:

    import macros, strutils
    
    macro abcProcs(n: varargs[expr]): stmt =
      result = newStmtList()
      for c in n.children:
        result.add parseStmt("proc $1 = echo \"$1\"" % $c)
    
    abcProcs("A","B","C")
    
    proc execute(order: openarray[int], callbacks: openarray[proc]) =
      for i in order:
        callbacks[i]()
    
    execute([0,0,1,2,1,2], [A,B,C])
Yes but on the plus side there's a lot fewer parentheses.
If you're counting tokens, you should count all of them: all symbols and punctuation, as well as any whitespace outside of a string literal that cannot be replaced by a single space character without affecting the syntax.
So APL is your favourite language then? :)

You should somehow measure cognitive load. Of course it should be measured on someone fluent in that language - but there should be an adjustment to factor in the cost of becoming fluent. :)

APL is about being obsessive with character count. We can turn any language into "APL" by giving the core functions one-letter names and using the lack of whitespace between them in some semantic role like chained application or whatever.

Hey look, "FUBAR". Take the first item, unwrap the list, bind it to function A as the first argument, then reverse! This kind of character-level reduction I'm not interested in at all; It's computer science puberty.

I never said "way too long" but rather "way too cumbersome". What is cumbersome in the Nimrod is the awkward encapsulation. For example, we have to create a special kind of list of statements with a special constructor. This list is a "bag-like" container with an .add method. Yuck!

You were down-voted but I secretly agree.

wait - oops. :)