Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Syntax Question

7 views
Skip to first unread message

Robert L.

unread,
Mar 16, 2018, 5:55:37 PM3/16/18
to
Edi Weitz wrote:

> > In the code below, the call (in caps) to helper gives me the error
> > "Variable HELPER has no value". Am working on transitioning from
> > scheme to lisp. Could someone explain why it believes helper has no
> > value? Thank you!
> >
> > (defun adj-list-to-edge-list (edgelst)
> > (let (
> > (helper (lambda (edges node)
> > (cond ((null edges) nil)
> > (t (cons (list node (first edges))
> > (HELPER (rest edges)
> > node))))))
> > )
> > (cond ((null edgelst) nil)
> > (t (append (funcall helper
> > (rest (first edgelst))
> > (first (first edgelst)))
> > (adj-list-to-edge-list (rest
> > edgelst)))))))
> >
> > Examples of how code works:
> > (defparameter adjlist '((a b c) (b e) (c d) (d b c e)
> > (e d f h) (f e) (g h) (h e g)))
> >
> > (adj-list-to-edge-list '((a b))) => ((A B))
> > (adj-list-to-edge-list '((a b c d))) => ((A B) (A C) (A D))
> > (adj-list-to-edge-list adjlist) => ((A B) (A C) (B E) (C D) (D B) (D C)
> > (D E) (E D) (E F) (E H) (F
> > E) (G H)
> > (H E) (H G))
>
> It would be somewhat shorter do write it like this
>
> (defun foo (list)
> (loop for (first . rest) in list
> nconc (loop for x in rest
> collect (list first x))))
>
> if I understand you correctly.

(define (foo a-list)
(append-map
(lambda (lst) (map (curry list (car lst)) (cdr lst)))
a-list))

(foo '((a b c) (b e) (c d) (d b c e) (e d f h) (f e) (g h) (h e g)))
===>
'((a b)
(a c)
(b e)
(c d)
(d b)
(d c)
(d e)
(e d)
(e f)
(e h)
(f e)
(g h)
(h e)
(h g))

--
Professor Goldman ... claimed that he and "most historians" regarded history
as a "weapon" to be used for "determining people's ideas and attitudes."
--- Revilo P. Oliver, "The Price of the Head"
Who controls the past ... controls the future: who controls the present
controls the past. --- Orwell http://archive.org/details/nolies
0 new messages