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

Re: anonymous functions

15 views
Skip to first unread message

WJ

unread,
Oct 24, 2015, 12:47:40 PM10/24/15
to
Why this is marked as abuse? It has been marked as abuse.
Report not abuse
Pascal Bourguignon wrote:

> > just a quick question. Let's say I have a list of numbers and a
> > variable bounded to another number. Is it possible to compare each
> > number of the list with the variable using anonymous functions instead
> > of loops, etc...also can it be done with letters too?
>
> Your specifications are rather imprecise. Do you mean this:
>
> (let ((a-list-of-numbers '(1 37 42 442 1024))
> (a-variable-bounded-to-another-number 42))
> (mapcar (lambda (a-number)
> (cond ((= a-number a-variable-bounded-to-another-number) '=)
> ((< a-number a-variable-bounded-to-another-number) '<)
> (t '>))) a-list-of-numbers))
> --> (< < = > >)

Gauche Scheme:

(let ((a-list-of-numbers '(1 37 42 442 1024))
(a-variable-bound-to-another-number 42))
(map
(^n (ref '(< = >) (+ 1 (compare n a-variable-bound-to-another-number))))
a-list-of-numbers))

(< < = > >)

--
They agitate for "equality" to facilitate the imposition of their own
immeasurable superiority, and for "economic justice" to mask their conviction
that all the property in the world justly belongs to them.... They denounce
"racism" and agitate for "human rights," with the secret reservation that they
are the only race that is human. --- R. P. Oliver

WJ

unread,
Oct 30, 2015, 2:43:43 PM10/30/15
to
WJ wrote:

> Pascal Bourguignon wrote:
>
> > > just a quick question. Let's say I have a list of numbers and a
> > > variable bounded to another number. Is it possible to compare each
> > > number of the list with the variable using anonymous functions instead
> > > of loops, etc...also can it be done with letters too?
> >
> > Your specifications are rather imprecise. Do you mean this:
> >
> > (let ((a-list-of-numbers '(1 37 42 442 1024))
> > (a-variable-bounded-to-another-number 42))
> > (mapcar (lambda (a-number)
> > (cond ((= a-number a-variable-bounded-to-another-number) '=)
> > ((< a-number a-variable-bounded-to-another-number) '<)
> > (t '>))) a-list-of-numbers))
> > --> (< < = > >)

MatzLisp (Ruby):

list = 1, 37, 42, 442, 1024
var = 42
list.map{|n| [:"=", :>, :<][n <=> var]}
==>[:<, :<, :"=", :>, :>]

--
Let us be brought to believe it is ... favorable to ... our interest to
transfer the African to his native clime, and we shall find a way to do it,
however great the task may be. --- A. Lincoln, Sept. 22, 1856

WJ

unread,
Jun 28, 2016, 3:34:26 AM6/28/16
to
WJ wrote:

> Pascal Bourguignon wrote:
>
> > > just a quick question. Let's say I have a list of numbers and a
> > > variable bounded to another number. Is it possible to compare each
> > > number of the list with the variable using anonymous functions instead
> > > of loops, etc...also can it be done with letters too?
> >
> > Your specifications are rather imprecise. Do you mean this:
> >
> > (let ((a-list-of-numbers '(1 37 42 442 1024))
> > (a-variable-bounded-to-another-number 42))
> > (mapcar (lambda (a-number)
> > (cond ((= a-number a-variable-bounded-to-another-number) '=)
> > ((< a-number a-variable-bounded-to-another-number) '<)
> > (t '>))) a-list-of-numbers))
> > --> (< < = > >)
>
> Gauche Scheme:
>
> (let ((a-list-of-numbers '(1 37 42 442 1024))
> (a-variable-bound-to-another-number 42))
> (map
> (^n (ref '(< = >) (+ 1 (compare n a-variable-bound-to-another-number))))
> a-list-of-numbers))
>
> (< < = > >)

OCaml:

let list = [1;37;42;442;1024] and
num = 42 in
List.map
(fun n -> List.nth ["<";"=";">"] (succ (compare n num)))
list ;;

["<"; "<"; "="; ">"; ">"]

--
[A]n unholy alliance of leftists, capitalists, and Zionist supremacists has
schemed to promote immigration and miscegenation with the deliberate aim of
breeding us out of existence in our own homelands.... [T]he real aim stays the
same: the biggest genocide in human history.... --- Nick Griffin
(https://www.youtube.com/watch?v=K0hD7IffTJs)
0 new messages