Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.lisp
Re: Multivalue tail recursion?
William James
12/28/2015 5:39:00 PM
> > Loops like:
> >
> > (loop for x below 10 collect x)
>
> range(10)
MatzLisp (Ruby):
(0..9).to_a
==>[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>
> >
> > (loop for x in '(3 5 7)
> > for y in '(2 5 8)
> > when (= x y)
> > collect (cons x y))
> >
>
> [(x, y) for x, y in zip([3,5,7], [2,5,8])
> if x == y]
[0,4,6,7].zip([2,4,5,7]).select{|a,b| a==b}
==>[[4, 4], [7, 7]]
>
> > (defun lookup (key table)
> > (loop for (ind val) in table
> > when (eq key ind)
> > return val))
>
> def lookup (key, table):
> for ind, val in table.iteritems():
> if key == ind: return val
def lookup key, table
(table.find{|k,v| k==key} || []).last
end
lookup :b, [[:a,2],[:b,3]]
==>3
lookup :xxx, [[:a,2],[:b,3]]
==>nil
Another way:
def lookup key, table
table.each{|k,v| return v if k==key}
nil
end
lookup :b, [[:a,2],[:b,3]]
==>3
lookup :xxx, [[:a,2],[:b,3]]
==>nil
Another way:
def lookup key, table
(table.assoc(key) || []).last
end
lookup :b, [[:a,2],[:b,3]]
==>3
lookup :xxx, [[:a,2],[:b,3]]
==>nil
--
Amazon bans book. After nearly a month on the site, all traces of the book and
its 80 reviews have been removed.
http://jamesfetzer.blogspot.com/2015/11/debunking-sandy-hook-debunk...
https://www.youtube.com/watch?v=E...
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: Multivalue tail recursion?
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password