Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.lisp
PicoLisp - iterate list
Jens Kallup
2/14/2016 9:14:00 PM
Hello Group,
I use PicoLisp under Linux 64-Bit.
Now, I would like iterate a lists,
that contains various information.
As example: a string, and a Object
Please have a look at the website:
http://fpaste.org/322605...
I would like search peoples in a
given City - Eisenach.
So my idea was it, search Eisenach
and then the Menschen. That is ok,
line: 116. But I need to check the
object Eisenach -- if kallup lives
there, then I would like to output
this.
Hope you can understand my poor
english, so sorry.
TIA
Jens
3 Answers
Pascal J. Bourguignon
3/7/2016 9:07:00 PM
0
Jens Kallup <jkallup@web.de> writes:
> Hello Group,
>
> I use PicoLisp under Linux 64-Bit.
There's really no good reason to use PicoLisp nowadays.
If money is a problem for you, go to the street, extend your hand, wait
a little, and you should soon enough have 5 euros to buy a Raspberry Pi
Zero, and run some Common Lisp implementation on it (ccl or ecl should
do fine).
> Now, I would like iterate a lists,
> that contains various information.
> As example: a string, and a Object
(defclass object ()
())
(dolist (item (list "Hello" (make-instance 'object)))
(print item))
prints:
"Hello"
#<object #x3020020D59ED>
> Please have a look at the website:
>
http://fpaste.org/322605...
Sorry, no it's too harsh on our eyes.
> I would like search peoples in a
> given City - Eisenach.
> So my idea was it, search Eisenach
> and then the Menschen. That is ok,
> line: 116. But I need to check the
> object Eisenach -- if kallup lives
> there, then I would like to output
> this.
(defclass named-object ()
((name :initarg :name :accessor name)))
(defclass city (named-object)
((inhabitants :initform '() :initarg :inhabitants :accessor inhabitants)))
(defclass man (named-object)
())
(defparameter *cities* (list (make-instance 'city :name "Eisenach")
(make-instance 'city :name "Muenchen")
(make-instance 'city :name "Paris")))
(defparameter *pascal* (make-instance 'man :name "Pascal"))
(defparameter *kallup* (make-instance 'man :name "Kallup"))
(defparameter *katja* (make-instance 'man :name "Katja"))
(push *pascal* (inhabitants (third *cities*)))
(push *kallup* (inhabitants (first *cities*)))
(push *katja* (inhabitants (first *cities*)))
(defmethod lives-in ((person man) (where city))
(format t "~A lives in ~A~%" (name person) (name where)))
(dolist (city *cities*)
(dolist (person (inhabitants city))
(lives-in person city)))
prints:
Katja lives in Eisenach
Kallup lives in Eisenach
Pascal lives in Paris
And now:
(name (find *kallup* *cities*
:key (function inhabitants)
:test (function member)))
returns:
"Eisenach"
> Hope you can understand my poor
> english, so sorry.
Better than PicoLisp.
Have a look at
http:/...
http:/...
/Getting+Started
http://gigamonkeys...
--
__Pascal Bourguignon__
William James
3/8/2016 1:23:00 AM
0
Pascal J. Bourguignon wrote:
> > I would like search peoples in a
> > given City - Eisenach.
> > So my idea was it, search Eisenach
> > and then the Menschen. That is ok,
> > line: 116. But I need to check the
> > object Eisenach -- if kallup lives
> > there, then I would like to output
> > this.
>
>
> (defclass named-object ()
> ((name :initarg :name :accessor name)))
>
> (defclass city (named-object)
> ((inhabitants :initform '() :initarg :inhabitants :accessor inhabitants)))
>
> (defclass man (named-object)
> ())
>
> (defparameter cities (list (make-instance 'city :name "Eisenach")
> (make-instance 'city :name "Muenchen")
> (make-instance 'city :name "Paris")))
>
> (defparameter pascal (make-instance 'man :name "Pascal"))
> (defparameter kallup (make-instance 'man :name "Kallup"))
> (defparameter katja (make-instance 'man :name "Katja"))
>
> (push pascal (inhabitants (third cities)))
> (push kallup (inhabitants (first cities)))
> (push katja (inhabitants (first cities)))
>
> (defmethod lives-in ((person man) (where city))
> (format t "~A lives in ~A~%" (name person) (name where)))
>
> (dolist (city cities)
> (dolist (person (inhabitants city))
> (lives-in person city)))
>
> prints:
>
> Katja lives in Eisenach
> Kallup lives in Eisenach
> Pascal lives in Paris
>
>
>
> And now:
>
> (name (find kallup cities
> :key (function inhabitants)
> :test (function member)))
>
> returns:
>
> "Eisenach"
MatzLisp (Ruby):
Man = Struct.new(:name)
City = Struct.new(:name, :inhabitants) do
def add person
self.inhabitants ||= []
self.inhabitants << person
end
def each_inhabitant
if inhabitants
inhabitants.each{|x| yield x}
end
end
end
$cities = [City.new("Eisenach"),
City.new(:name => 'Muenchen'),
City.new('Paris')]
$pascal = Man.new('Pascal')
$kallup = Man.new('Kallup')
$katja = Man.new("Katja")
$cities[2].add $pascal
$cities[0].add $kallup
$cities[0].add $katja
$cities.each{|city|
city.each_inhabitant{|man| puts "#{man.name} lives in #{city.name}"}}
===>
Kallup lives in Eisenach
Katja lives in Eisenach
Pascal lives in Paris
$cities.find{|x| x.inhabitants.include? $kallup}.name
===>
"Eisenach"
--
Goyim were born only to serve us. Without that, they have no place in the
world---only to serve the People of Israel.... They will work, they will plow,
they will reap. We will sit like an effendi and eat. --- Rabbi Ovadia Yosef
http://archive.org/download/DavidDuke_videos/TopRabbiExposesJewishRacism-cybsd...
https://web.archive.org/web/20101020044210/http://www.jpost.com/JewishWorld/JewishNews/Article.aspx...
Paul Rubin
3/13/2016 8:01:00 AM
0
"Pascal J. Bourguignon" <pjb@informatimago.com> writes:
> There's really no good reason to use PicoLisp nowadays.
PicoLisp is technically cool, but sadly I think you're right about its
usefulness and I wonder if it was even that worthwhile in the past,
compared with CLisp or some of the Schemes or embedded Lisps out there.
>> Please have a look at the website:
>>
http://fpaste.org/322605...
>...
> Sorry, no it's too harsh on our eyes.
> (defclass named-object ()
I find both the PicoLisp and CL implementations confusing, what with all
those classes and redundant code. It makes me want a library that lets
you make arrays of records and do SQL-like queries on them. It wouldn't
surprise me if there's something like that out there.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
PicoLisp - iterate list
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