William James
5/24/2016 11:39:00 PM
WJ wrote:
> 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.
> >
> > Don't try to translate from Scheme to CL verbatim, try to learn the
> > language constructs CL has to offer.
>
> Gauche Scheme:
>
> (define (foo lists)
> (append-map
> (lambda (xs) (map (cut list (car xs) <>) (cdr xs)))
> lists))
>
> (foo '((a b c d) (x y z) (q p)))
> ===>
> ((a b) (a c) (a d) (x y) (x z) (q p))
>
>
> Another way:
>
> (use srfi-42 :only (list-ec))
>
> (define (foo lists)
> (list-ec
> (: xs lists)
> (: y (cdr xs))
> (list (car xs) y)))
OCaml:
let foo lists =
lists
|> List.map (fun (x::xs) -> List.map (fun y -> x,y) xs)
|> List.concat ;;
foo [["a";"b";"c";"d"];["x";"y";"z"];["q";"p"]] ;;
===>
[("a", "b"); ("a", "c"); ("a", "d"); ("x", "y"); ("x", "z"); ("q", "p")]
--
Again, commenters focused on the double standard whereby Jews advocate
multiculturalism and immigration for Europe, but have Israel as an avowedly
Jewish state to fall back on...
theoccidentalobserver.net/2015/11/douglas-murrays-warning-to-the-jewish-community