Arc Forumnew | comments | leaders | submitlogin
Let over lambda, ch 5 (declare (ignorable x))
2 points by cthammett 3261 days ago | 6 comments
Good Morning Ladies and Gentlemen. First of all please forgive me if this question has already been answered in another thread. What is the anarki equivalent of (declare (ignorable x)). Please find respectively: the relevant macro, it's application and the output below.

  (defmacro tree-leaves (tree test result)
    `(tree-leaves%%
       ,tree
       (lambda (x)
         (declare (ignorable x))
         ,test)
       (lambda (x)
         (declare (ignorable x))
         ,result)))

  (tree-leaves
      '(1 2 (3 4 (5 . 6)))
      (and (numberp x) (evenp x))
      'even-number)

  (1 EVEN-NUMBER (3 EVEN-NUMBER (5 . EVEN-NUMBER)))
Help is greatly appreciated. The following is a link to the page: http://letoverlambda.com/index.cl/guest/chap5.html#sec_7


3 points by cthammett 3261 days ago | link

  ;tree-leaves function for modifying leaves with plug-in test
  (def t-l%% (tree test result)
    (if tree
      (if (alist tree)
        (cons
          (t-l%% (car tree) test result)
          (t-l%% (cdr tree) test result))
        (if (test tree)
          (result tree)
        tree))))

  ;Modified akkartik's solution
  (mac t-l (tree test result)
    `(t-l%% ,tree 
      (fn (x) ,test) 
      (fn (x) ,result)))

  ;Using the following input
  (t-l `(1 2 (3 4 (5 6))) (and (number x) (even x)) 'even-number)

  ;Results
  (1 even-number (3 even-number (5 even-number)))

-----

1 point by akkartik 3261 days ago | link

Arc/anarki is more minimalist than common lisp and won't warn you about unused variables, so I think the answer here is: nothing :) Here's the equivalent macro in anarki:

  (mac tree-leaves (tree test result)
    `(tree-leaves%% ,tree ,test ,result))
Might as well call the function directly :)

(And no, this wasn't asked before. I'd never gotten past the first couple of chapters of letoverlambda. Maybe I should go back to it.)

-----

2 points by cthammett 3261 days ago | link

Hey thank you this is very helpful for beginners like me. I am working through it to learn, practice and master the ideas presented in the book.

-----

1 point by akkartik 3261 days ago | link

You're welcome. By the way, if you add two spaces to a line on this forum it won't run through with the next one. Compare these two examples:

line1 line2

  line1
  line2
This is useful when showing code.

Feel free to ask more questions!

-----

2 points by cthammett 3255 days ago | link

Hey thanks for saving me further embarrassment. If I were to ask another question should I start another thread? In particular I am trying to translate to arc a matching function in Paul Graham's On Lisp, Fig 18.5. After this I am hoping to learn about Query Interpreters Fig 19.3 and Query Compilers Fig 19.6

-----

1 point by akkartik 3255 days ago | link

Whatever you like! Don't worry about dominating the frontpage or anything. Feel free to open new threads as needed.

-----