Discussion:
I still do not know lisp
(too old to reply)
Bigos
2020-03-29 14:01:53 UTC
Permalink
I have been occasionally playing with lisp for more than half of a decade.

Today I have run this code:

(defparameter tclass (cadr (sb-mop:compute-class-precedence-list
(class-of 'symbol)))
"find T which is the top class of SBCL object system")

(defun class-children (obj)
(list obj
(loop
for cl in
(sb-mop:class-direct-subclasses obj)
collect
(list (class-children cl)))))

REPL> (class-children tclass)

And the result has amazed me.
Bigos
2020-03-29 17:48:30 UTC
Permalink
Post by Bigos
I have been occasionally playing with lisp for more than half of a decade.
(defparameter tclass (cadr (sb-mop:compute-class-precedence-list
                            (class-of 'symbol)))
  "find T which is the top class of SBCL object system")
(defparameter tclass (find-class 'T)
"find T which is the top class of SBCL object system")
Post by Bigos
(defun class-children (obj)
  (list obj
        (loop
           for cl in
             (sb-mop:class-direct-subclasses obj)
           collect
             (list (class-children cl)))))
REPL> (class-children tclass)
And the result has amazed me.
Barry Margolin
2020-03-30 13:51:33 UTC
Permalink
Post by Bigos
I have been occasionally playing with lisp for more than half of a decade.
(defparameter tclass (cadr (sb-mop:compute-class-precedence-list
(class-of 'symbol)))
"find T which is the top class of SBCL object system")
(defun class-children (obj)
(list obj
(loop
for cl in
(sb-mop:class-direct-subclasses obj)
collect
(list (class-children cl)))))
REPL> (class-children tclass)
And the result has amazed me.
You seem to be creating lots of extraneous lists. CLASS-CHILDREN returns
a list, there's no need to call LIST around the recursive calls.
--
Barry Margolin, ***@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
Bigos
2020-03-30 17:11:32 UTC
Permalink
Post by Barry Margolin
You seem to be creating lots of extraneous lists. CLASS-CHILDREN returns
a list, there's no need to call LIST around the recursive calls.
Yes, I seem to go too far :-D

And my code is messy. I was learning to debug SBCL programs.

https://github.com/bigos/traverser/blob/master/traverser.lisp
Robert L.
2020-04-07 20:44:49 UTC
Permalink
Post by Bigos
(defun class-children (obj)
(list obj
(loop
for cl in
(sb-mop:class-direct-subclasses obj)
collect
(list (class-children cl)))))
(defun class-children (obj)
(list obj
(mapcar #'class-children
(sb-mop:class-direct-subclasses obj))))

Paul Graham:

I consider Loop one of the worst flaws in CL, and an example
to be borne in mind by both macro writers and language designers.
--
The report card by the American Society of Civil Engineers showed the national
infrastructure a single grade above failure, a step from declining to the point
where everyday things simply stop working the way people expect them to.
http://archive.org/details/nolies
Bigos
2020-04-09 21:33:46 UTC
Permalink
Post by Bigos
(defun class-children (obj)
(list obj
(mapcar #'class-children
(sb-mop:class-direct-subclasses obj))))
I consider Loop one of the worst flaws in CL, and an example
to be borne in mind by both macro writers and language designers.
Compared side by side you version with mapcar is shorter.

But the loop version is closer to the way my twisted mind thinks.
Perhaps that is the problem?
Bigos
2020-04-10 00:41:17 UTC
Permalink
Post by Bigos
Post by Bigos
(defun class-children (obj)
   (list obj
     (mapcar #'class-children
             (sb-mop:class-direct-subclasses obj))))
I consider Loop one of the worst flaws in CL, and an example
to be borne in mind by both macro writers and language designers.
Compared side by side you version with mapcar is shorter.
But the loop version is closer to the way my twisted mind thinks.
Perhaps that is the problem?
If I tried to untangle my mind, what programming style constraints would
you suggest?

In OO programming some people suggest to do a project without using IF
but using the object system.
Nelson Alexandra
2020-04-14 17:48:00 UTC
Permalink
Post by Bigos
[...]
[...]
[...]
If I tried to untangle my mind, what programming style constraints
would you suggest?
In OO programming some people suggest to do a project without using IF
but using the object system.
You mean the polymorphism decides what function is used?

Definition [1]:
Say you have a category and objects A, B, C. Then a coproduct of
A and B is an object (written A+B) such that there are injections
iA : A -> A+B and iB : B -> A+B and for any two morphisms f : A -> C
and g : B -> C there is a unique morphism [f,g] : A+B -> C such that the
following diagram communtes ( g = [f,g] o iA, f = [f,g] o iB):

A -iA -> A+B <- iB- B
\ | /
\ [f,g] /
g\ | /f
v v v
C

[f,g] is the if-then-else or a polymorphism or a generic function in
lisp I guess. A,B,C are OO objects classes.

Taking Seibel's [2] shape example:

(defgeneric draw (shape)
(:documentation "Draw the given shape on the screen."))

is the polymorphism or if-then-else.

(defmethod draw ((shape circle)) ...)
(defmethod draw ((shape triangle)) ...)

are the morphisms f and g.

I'm not sure what C might be.

Perhaps with multimethods A+B is replaced by a polynomial like
(A1+A2) x (B1+B2+B3).

[1]
https://en.wikipedia.org/wiki/Coproduct
[2]
http://www.gigamonkeys.com/book/object-reorientation-generic-functions.html
Stefan Monnier
2020-04-10 03:21:23 UTC
Permalink
Post by Bigos
But the loop version is closer to the way my twisted mind thinks.
Perhaps that is the problem?
Could be. It seems your mind is used to thinking in terms of "what the
CPU should do" instead of "what the result should look like".

FWIW I usually don't like the `loop` macro very much, so I'm clearly
biased, but I thought your use of `loop` was clearly within the `ugly`
group since it maps so cleanly to simpler loops like `mapcar`.


Stefan
Bigos
2020-04-10 17:25:19 UTC
Permalink
Post by Stefan Monnier
Post by Bigos
But the loop version is closer to the way my twisted mind thinks.
Perhaps that is the problem?
Could be. It seems your mind is used to thinking in terms of "what the
CPU should do" instead of "what the result should look like".
FWIW I usually don't like the `loop` macro very much, so I'm clearly
biased, but I thought your use of `loop` was clearly within the `ugly`
group since it maps so cleanly to simpler loops like `mapcar`.
Stefan
I have solved some convoluted algorithm puzzles in the past.
I used loop and I do not know how to solve it efficiently with mapcar
and its cousins.

As I said in the other post, programming with certain constraints could
be the way out.
Paul Rubin
2020-04-10 23:01:10 UTC
Permalink
Post by Bigos
I have solved some convoluted algorithm puzzles in the past.
I used loop and I do not know how to solve it efficiently with mapcar
and its cousins.
No idea about those particular puzzles, but in general, a purely
functional approach often calls for completely different algorithms.
Haskell programmers get used to this. There is a very good book,
"Purely Functional Data Structures" by Chris Okasaki, that goes into how
to do it.
Azathoth Hastur
2020-04-18 00:55:30 UTC
Permalink
Post by Paul Rubin
Post by Bigos
I have solved some convoluted algorithm puzzles in the past.
I used loop and I do not know how to solve it efficiently with mapcar
and its cousins.
No idea about those particular puzzles, but in general, a purely
functional approach often calls for completely different algorithms.
Haskell programmers get used to this. There is a very good book,
"Purely Functional Data Structures" by Chris Okasaki, that goes into how
to do it.
https://tpb.party/torrent/8156082/Purely_Functional_Data_Structures_By_Chris_Okasaki_[PDF]

you are the man for bringing this up!
could you form a supercomputing cluster from these?
Bigos
2020-04-13 23:29:14 UTC
Permalink
Post by Stefan Monnier
Post by Bigos
But the loop version is closer to the way my twisted mind thinks.
Perhaps that is the problem?
Could be. It seems your mind is used to thinking in terms of "what the
CPU should do" instead of "what the result should look like".
FWIW I usually don't like the `loop` macro very much, so I'm clearly
biased, but I thought your use of `loop` was clearly within the `ugly`
group since it maps so cleanly to simpler loops like `mapcar`.
Stefan
I was going through a list or rules and initially started with a loop
macro. Soon it became difficult to rewrite and reason about other
approaches.

Lesson learned.
Kaz Kylheku
2020-04-14 06:16:28 UTC
Permalink
Post by Bigos
Lesson learned.
The main lesson here is that rewriting code just for the hell of it is
high risk, low benefit.

Here, the working code of the form:

(loop for x in y collect (list (f x)))

was replaced by the inequivalent code:

(mapcar #'f y)
Po Lu
2020-04-21 09:04:39 UTC
Permalink
Post by Stefan Monnier
Could be. It seems your mind is used to thinking in terms of "what the
CPU should do" instead of "what the result should look like".
I won't dispute that `loop' is useful in some cases. However as someone
who is more or less a Scheme person I think `loop' is much overused.
Post by Stefan Monnier
FWIW I usually don't like the `loop` macro very much, so I'm clearly
biased, but I thought your use of `loop` was clearly within the `ugly`
group since it maps so cleanly to simpler loops like `mapcar`.
Indeed! The tendency to overuse `loop' for trivial tasks is a rather
sad symptom of Common Lisp programmer's disease.
Bigos
2020-04-21 16:39:55 UTC
Permalink
Post by Po Lu
Post by Stefan Monnier
Could be. It seems your mind is used to thinking in terms of "what the
CPU should do" instead of "what the result should look like".
I won't dispute that `loop' is useful in some cases. However as someone
who is more or less a Scheme person I think `loop' is much overused.
Post by Stefan Monnier
FWIW I usually don't like the `loop` macro very much, so I'm clearly
biased, but I thought your use of `loop` was clearly within the `ugly`
group since it maps so cleanly to simpler loops like `mapcar`.
Indeed! The tendency to overuse `loop' for trivial tasks is a rather
sad symptom of Common Lisp programmer's disease.
But I am on the path towards recovery.

I was playing with some recursive functions last night and realized that
loop was obscuring some possibilities of having elegant solutions.
Kaz Kylheku
2020-04-21 17:02:09 UTC
Permalink
Post by Po Lu
Post by Stefan Monnier
Could be. It seems your mind is used to thinking in terms of "what the
CPU should do" instead of "what the result should look like".
I won't dispute that `loop' is useful in some cases. However as someone
who is more or less a Scheme person I think `loop' is much overused.
Post by Stefan Monnier
FWIW I usually don't like the `loop` macro very much, so I'm clearly
biased, but I thought your use of `loop` was clearly within the `ugly`
group since it maps so cleanly to simpler loops like `mapcar`.
Indeed! The tendency to overuse `loop' for trivial tasks is a rather
sad symptom of Common Lisp programmer's disease.
Why; it's readable and runs fast, compiling to elementary operations
like stepping variabled and goto: no lambdas to be analyzed for
non-escaping and whatnot.

Loop syntax arguably makes a Lisp code base more welcoming to newcomers
who don't yet grok a mouthful of recursion and point-free style.

Also, Lisp is often wrongly attacked for being impractical, requiring
all repetitive processing to be done with recursion (because that's all
that some people learn in a so-called Lisp course: possibly a course
based on Scheme). I've seen this nonsense trotted out countless times,
and one good counterargument is a Loop example.

(macroexpand '(loop ...)) is also great for showing newbies the gist
of how macros can add non-trivial features to a language.

Even if you eschew Loop in code, you can use it in debate and
in Lisp education.
--
TXR Programming Lanuage: http://nongnu.org/txr
Music DIY Mailing List: http://www.kylheku.com/diy
ADA MP-1 Mailing List: http://www.kylheku.com/mp1
Bigos
2020-04-24 09:56:41 UTC
Permalink
Post by Kaz Kylheku
Post by Po Lu
Post by Stefan Monnier
Could be. It seems your mind is used to thinking in terms of "what the
CPU should do" instead of "what the result should look like".
I won't dispute that `loop' is useful in some cases. However as someone
who is more or less a Scheme person I think `loop' is much overused.
Post by Stefan Monnier
FWIW I usually don't like the `loop` macro very much, so I'm clearly
biased, but I thought your use of `loop` was clearly within the `ugly`
group since it maps so cleanly to simpler loops like `mapcar`.
Indeed! The tendency to overuse `loop' for trivial tasks is a rather
sad symptom of Common Lisp programmer's disease.
Why; it's readable and runs fast, compiling to elementary operations
like stepping variabled and goto: no lambdas to be analyzed for
non-escaping and whatnot.
Loop syntax arguably makes a Lisp code base more welcoming to newcomers
who don't yet grok a mouthful of recursion and point-free style.
Also, Lisp is often wrongly attacked for being impractical, requiring
all repetitive processing to be done with recursion (because that's all
that some people learn in a so-called Lisp course: possibly a course
based on Scheme). I've seen this nonsense trotted out countless times,
and one good counterargument is a Loop example.
(macroexpand '(loop ...)) is also great for showing newbies the gist
of how macros can add non-trivial features to a language.
Even if you eschew Loop in code, you can use it in debate and
in Lisp education.
Alternatives, knowing their pros and cons in different circumstances
counts can be handy.

We tend to create a mental map of our reality, but the map is not the
territory, so at the end of the day, endless discussions about pros and
cons of loops may go too far and interesting discussion about different
points of view may turn into political argument.

Did someone ever try to start a LOOP party?
t***@google.com
2020-04-24 17:27:39 UTC
Permalink
Post by Bigos
Did someone ever try to start a LOOP party?
II wanted to, but was afraid I'd never get out of it.
:)
Bigos
2020-04-25 14:58:17 UTC
Permalink
Post by t***@google.com
Post by Bigos
Did someone ever try to start a LOOP party?
II wanted to, but was afraid I'd never get out of it.
:)
ROTFL!!!
Kaz Kylheku
2020-04-25 15:21:48 UTC
Permalink
Post by Bigos
Post by t***@google.com
Post by Bigos
Did someone ever try to start a LOOP party?
II wanted to, but was afraid I'd never get out of it.
:)
ROTFL!!!
And then old Hofstadter shows up and it turns into a Strange Loop party.
Azathoth Hastur
2020-04-18 00:52:21 UTC
Permalink
Post by Bigos
Post by Bigos
(defun class-children (obj)
(list obj
(loop
for cl in
(sb-mop:class-direct-subclasses obj)
collect
(list (class-children cl)))))
(defun class-children (obj)
(list obj
(mapcar #'class-children
(sb-mop:class-direct-subclasses obj))))
I consider Loop one of the worst flaws in CL, and an example
to be borne in mind by both macro writers and language designers.
--
The report card by the American Society of Civil Engineers showed the national
infrastructure a single grade above failure, a step from declining to the point
where everyday things simply stop working the way people expect them to.
http://archive.org/details/nolies
AWESOME!!
more graham!!
I wonder what he thinks of picolisp?
Azathoth Hastur
2020-04-18 00:51:38 UTC
Permalink
Post by Bigos
I have been occasionally playing with lisp for more than half of a decade.
(defparameter tclass (cadr (sb-mop:compute-class-precedence-list
(class-of 'symbol)))
"find T which is the top class of SBCL object system")
(defun class-children (obj)
(list obj
(loop
for cl in
(sb-mop:class-direct-subclasses obj)
collect
(list (class-children cl)))))
REPL> (class-children tclass)
And the result has amazed me.
stop doing object programming and stick to fucntional
Loading...