libera/#commonlisp - IRC Chatlog
Search
4:29:27
kakuhen
pjb: regarding the macro from yesterday, it seems that restart-case does not place forms on the top level, and the cl spec only guarantees types exist when you defclass on the top level; it seems you can have implementation-specific behavior when you defclass below the top level
7:30:25
pjb
kakuhen: note that restart case in foo could have only been invoked by the compiler, since it wraps only defclass and defmethod.
9:02:20
lotuseater
Hey does anyone know this Automated Mathematician system by Douglas Lenat? (from which Cycorp more or less evolved)
9:10:56
edgar-rft
lotuseater: wasn't that one of the predecessor ideas that later became known under the term "genetic programming" (automatically generating, modifying and testing computer source code)?
9:12:15
lotuseater
and first read about this system indirectly in Gödel Escher Bach by Douglas Hofstadter some time ago. to me personally very interesting as it also touches experimental mathematics
9:14:28
lotuseater
the great mathematicians like Euler, Gauss, etc were all experimental mathematicians in the first part of their work pipeline
9:15:19
lotuseater
so I found an archived repo of AM translated from Lisp to Prolog but the file organization seems messy
9:29:42
hayley
Anyways, AM looks like an interesting project. In the context of CL programs, I considered a program which would just nudge things around to find dumb mistakes that I fail to find because I'm not thinking about them.
9:31:24
hayley
Well, his shtick is that abstraction is a net loss would you flip through lots of codebases, or would you be a new programmer. But as Dijkstra said (paraphrasing) "the aim of abstraction is to make a layer that one can be totally precise about."
9:32:41
hayley
Without such a mechanism, one achieves a vulgar kind of simplicity where they can't do very much, even if the components are blatantly obvious in what they do. It's like less-is-less rather than less-is-more.
9:34:23
hayley
Should I shut up now? I could go on for a long time about how annoying it is that such a bad idea of "simplicity" permeates the minds of a lot of hackers.
10:47:54
jmercouris
better way than format for concatenating a list of strings into a single string?
11:01:24
jmercouris
I'm asking if there is a performance penalty or reason to prefer one or the other
11:09:17
hayley
Well, you know the size of the output string already, so you can allocate exactly the right size and fill it in.
11:10:42
hayley
c.f. fast-io being quite fast. I remember I wrote a faster-io as I knew I could get away with not copying some buffers, so I just stuck those into the list rather than copy them in.
11:11:50
hayley
How much are you concatenating though? Depending on the context you probably shouldn't care too much.
11:33:16
pjb
lotuseater: nothing new about CyC. I dug a little into OpenCyC some years ago, and indeed, everything that's said was apparent. The best thing they could do to unlock the situation would be to replace the pseudo-lisp->java translator by a pure CL implementation, then externalize the database (so it can be put in git). Then things could evolve…
11:35:17
pjb
jmercouris: (com.informatimago.common-lisp.cesarum.sequence:concatenate-sequences '(vector character) '("Foo" "Bar" "Baz")) #| --> "FooBarBaz" |#
11:37:43
pjb
jmercouris: there's also: (com.informatimago.common-lisp.cesarum.string:concatenate-strings '(("FooBar" 0 3) (#\b #\a #\z) (quux 2 4))) #| --> "FoobazUX" |#
11:50:15
etimmons
Xach: I was over optimistic on UIOP release timeline. I don't think it'll make it for this next QL. Maybe the random failures experienced by users will cause at least a few more folks to explicitly depend on UIOP if they use anything from it
12:35:24
jmercouris
but it seems I don't understand how to use the ~/ / directive because it complains that I am trying to pass 4 arguments to car
12:44:49
Bike
it's ~/function-name/, and the function has to take a particular argument convention so it can have commas and colons like other directives
12:47:09
Bike
i don't think there's any easy way to get format to print the cars of a list (without doing like (mapcar #'car ...) i mean obviously)
12:53:04
jackdaniel
when you navigate to the part of the spec that describes tilde left brace you will find out
12:58:49
ldb
find a interesting book about book composition using moveble type that mentioned how to typeset music scores
13:00:45
beach
There was only one book before that, namely that of Ross, but it was a lot less complete than Behind Bars.
13:17:12
ldb
That book describes how the staff is composed by many lines and elements, with movable type. I guess today with digital typesetting capable of doing overlapping, such a system would rarely been used.
13:26:14
nij-
Hi! I constantly run into situations where pattern matching is needed. Most of the time, I can get through it by writing adhoc looking codes.. but I think there must be a better way. So here's an example: how would you write pattern matching code for #'fun such that it groups a list of lists based on the cars?
13:26:20
nij-
(fun '((1 a b) (2 c d e) (3 f g) (1 h i j) (2 k))) ;; => ((1 a b h i j) (2 c d e k) (3 f g))
13:28:44
jmercouris
grouping a list of list based on the cars, sounds like a job for a H A S H T A B L E
13:28:54
heisig
nij-: I recommend Trivia for pattern matching. But what you describe isn't a pattern matching problem.
13:28:56
nij-
Yeah, the function itself isn't not about pattern matching logic. But I think my code can be much cleaner if written in the PM style.
13:29:41
nij-
no no.. the issue isn't how to implement #'fun.... but to implement it using a clean PM code.
13:29:58
hayley
That pattern rather matches positions, not elements with the same heads, as heisig said.
13:31:38
hayley
(loop for (key . values) in list do (stash-values key values) finally (return accumulated-values))
13:31:49
nij-
hayley: How would you use loop destructuring? I think that's some thing I haven't considered.
13:32:31
hayley
One good pattern matching problem would be a symbolic derivative function, or a term simplification function.
13:32:36
ldb
yes loop can destructuring, there are also variants to LET that can do destruct, probably described in Let over lambda
13:34:17
hayley
The DEFINE-RE macro I used for simplifying regular expressions even got some appraisal from one die-hard functional programmer. That would be where you want pattern matching.
13:38:46
nij-
I'm thinking about the possibility of turning regex's (for text) functionalities into lisp (for sexprs)..
13:39:09
nij-
But I need to come up with a harder problem, which couldn't be easily solved by desstructuring LOOP.
13:39:50
hayley
You want to parse the textual form of a RE? Or you want a RE which matches Lisp objects?
13:50:39
pjb
nij-: we cannot say what is required, because you've not written down any specification / requirements for your function. Only an example of call. If it's an exercise in learning list processing (car/cdr/cons), then no matching is needed. It's clear from your example, that we only test the first element of each sublist, by the way it's even of a different type!
13:52:23
pjb
nij-: some pattern matchers are actually regexp engines. (but often not, since you want to have unification, which is out of the scope of normal regexp engines).
13:52:41
pjb
nij-: some regexp engines are more generic than text processing (the theory is not restricted to text).
13:53:17
pjb
a pattern may contain variables. if the pattern is repeated, the variable must bind to the same values in all occurences.
13:53:22
nij-
Oh! I thought regexp is all about text. Do you mind pointing me to some things to read more about non-text regexps?
13:54:11
pjb
(* (foo ?a) (bar ?a) *) matches ((foo 42) (bar 33) #|>|# (foo 22) (bar 22) #|<|# (foo 33)) with ?a = 22
13:55:26
Bike
regexes can work on sequences that arne't full of characters just as well. fundamentals like the kleene star (*) is insensitive to what the sequence actually contains
13:56:55
_death
could do worse than read the latest from Sussman (Software Design for Flexibility).. it shows how to implement a bunch of pattern matchers
13:57:09
pjb
Well, you'd have to patch it to remove type checks: (handler-case (scan '(:greedy-repetition 2 6 #\b) #(33 #\b #\b #\c 42)) (error (err) (princ err))) --> The value 33 is not of the expected type character.
13:57:55
pjb
Note: (scan '(:greedy-repetition 2 6 #\b) #(#\b #\b #\b #\c #\a)) #| --> 0 ; 3 ; #() ; #() |#
13:59:52
nij-
Bike - say I want to collect every thing that's a struct that has a slot :SLOT whose value is 0.
14:00:04
pjb
for graph you'd need a little more complexity (you'd have to walk the different branches, and avoid duplicate subpaths), but dealing with acyclic structures (trees) is done routinely in pattern matchers.
14:00:24
Bike
are you talking about pattern matching? Because that doesn't really seem related to regular expressions to me, unless i'm missing something
14:03:45
_death
many Lisp books contain sections about implementing pattern matchers.. usually showing naive interpreter-like matchers and then moving on to compilation.. if you have a lot of patterns (or "rules") you can read about more advanced stuff like the RETE algorithm
14:04:31
nij-
Namely, if *x* is a struct whose :a contains 0, then extract it's value from the :b slot.
14:04:54
Bike
seems doable to me, though you might need mop support. i don't know if trivia has it built in though.
14:05:59
nij-
here, (list 0 1 __ 3) means any list that starts with 0 and 1, has 0 or more stuff in between, but ends with 3.
14:07:01
_death
I think pattern matchers (and unifiers) can be useful when the patterns are "data", i.e. not set in stone.. they are a nuisance in ordinary code, in my opinion.. so I don't like Haskell/Prolog/Erlang/etc. ordinary use of it
14:07:57
tfeb
you can't do that portably unless by 'struct' you really mean 'name of a class' (which seems to be what the trivia exam0le has)
14:08:49
nij-
This seems like a hard DSL design problem. The question isn't how to extend trivia for it to do that.
14:10:57
Bike
Oh, you want it to work for an instance of any class, as long as it has a slot of that name?
14:12:07
nij-
So the problem really is how to design a general enough DSL, or - has there been one already?
14:12:44
tfeb
it's also really smelly: my struct has an a field, so does yours, but they mean completely different things
14:13:33
Bike
The actual syntax for the DSL is pretty trivial, something like (ducktyped :a 0 :b y). there's the language design done, now it's just implementation
14:14:10
Bike
(although you might want to do like trivia and use slot names and accessors, rather than initargs)