libera/#commonlisp - IRC Chatlog
Search
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)
14:16:47
Bike
also i just remembered you wouldn't need MOP if you used slot names, since you can use slot-exists-p
14:18:17
_death
an old frame system called Parmenides also had a rule engine written for it, FRulekit.. it allowed some pattern matching in its rules (and implemented the rete algorithm).. with some effort, one could probably beat it into CLOS submission instead.. https://github.com/death/Parmenides/blob/master/FRulekit.md
14:26:32
ldb
There is Predicate Dispatching http://dspace.mit.edu/bitstream/handle/1721.1/7071/AITR-2001-006.pdf?sequence=2
16:57:46
pjb
lotuseater: well, it's said in the AMA, it's basically a subset of CyC, notably for the ontologies.
16:58:28
pjb
lotuseater: but what's interesting anyways, is that people who've spent time inside CyC say that the best option would be to rewrite it from scratch.
16:59:10
pjb
the ontologies shouldn't be developped manually. They should be infered with statistical ML applied on the web and youtube, and if you have access to robots, from robot action/sensors feedbacks.
17:00:57
pjb
The brain has clearly several layers, including ANN layers and symbolic layers. And furthermore, there are different kinds of learning. You can learn the table of multiplication (purely symbolic), and once you've learned it, it's "hardwired" into an ANN. And it can even generalize to multiple digit numbers.
17:01:56
pjb
And you can learn to walk, to talk or drive a bicycle, totally ANN ML, but with SOM and other class of ANN to raise symbolic (conscious) signals and command pathways.
17:03:05
pjb
And Douglas Hofstadter https://en.wikipedia.org/wiki/Category:Books_by_Douglas_Hofstadter should be studied and followed.
17:04:30
pjb
That said, CyC Inc is doing something right: exploiting commercially the classical AI algorithms. More companies should do that too, in addition to statistical AI.
17:26:30
phoe
I want to talk a little about code style and naming conventions in Common Lisp Recipes 2
17:30:58
lotuseater
afaik Cyc wants to be "more" than just normal inference engine, for putting in much details that are also situation dependent into it
17:31:43
lotuseater
"when there's one part of the rubik's cube at this position, none else can be there at the same time"
17:32:11
lotuseater
so for us humans much of this "obvious" stuff we learn by experiencing when growing up
17:39:07
phoe
the first and most important one is that there's no silver bullet for that, given the variety of coding styles and naming conventions that are around
17:40:06
phoe
the less established ones are %foo% for global symbol macros and =foo= or -foo- for global static variables
17:40:27
lotuseater
Josh_2: let alone the syntax highlighting, baggers brought me to this in one of his awesome videos
17:41:33
lotuseater
ah static variables is one of those points i have still to dig in, but i would use =foo= cause hyphens are mostly for multiple word symbols in between
17:45:20
phoe
but still, enough code uses +foo+ to make it mentionworthy, even if the CL package does not use it for +pi+ and such
17:51:06
lotuseater
other people find me weird when i told them "no for the meter per second function i simply use M/S and for the this lexical value i do (let ((5*10^5 (* 5 (expt 10 5)))) ...)
17:51:24
lisp123_
w.r.t to code conventions, its been something on my mind lately: the latest I have got to is that "lisp 2" way of doing things IMHO is very good. I name _all_ my variables the same name as the function that generates them. And then the parameters / arguments are also following the consistent naming, unless it makes it too, too long
17:54:23
_death
lotuseater: for the computation I'd likely just write 5e5 (but that would be a float)
17:55:34
phoe
_death: actually I don't have good news for you - I have no idea how to approach this problem, especially since footnotes are a matter of taste as well
17:55:50
phoe
but that's already a publishing kind of problem, and maybe #clcs will be a better venue to discuss this
17:56:52
lisp123_
lotuseater: what do you think :) I think its kinda done already (everytime one does (let ((list (list 1 2 3 )... for example
17:57:13
phoe
lisp123_: the first and most important goal is not to screw up what the first edition already achieved, and that's already a tough thing to do given how consistent CLR is as a book
17:58:08
_death
phoe: whenever there was a footnote, I felt compelled to read it, and then, disappointed, "why not just say what mean in the main text, clearly and succinctly?".. I could not bear to read the book to the end..
18:00:14
lisp123_
phoe: also it has quite a unique style. you can pick up any chapter of CLR, and quickly apply the examples to produce useful code. Good luck :) (would be great to give extended treatment of BKNR since that's one of my favourite packages lol, just throwing that in there)
18:00:48
phoe
lisp123_: yes, this is the idea - each recipe is meant to be fully independent on its own, and link everywhere else in the book for off-topic things
18:01:13
lisp123_
_death: don't say that, I use unicode extensively (for symbolic computation its a godsend) :O
18:01:33
_death
lotuseater: and for names like "alpha" etc. often a better name is, say, "learning-rate".. though often programmers deal with their mathematician jealousy by taking the bad habits, I know
18:03:03
lotuseater
and of course with no comment, so it's "obvious" lr means learning-rate in this context
18:03:26
lisp123_
phantomics: what programs do you build with unicode? math software? (I'm doing that)
18:03:34
tfeb
they're not bad habits: for a lsnguage (maths) designed to be handwritten, brevity matters a lot.
18:04:04
_death
that said I do sometimes use greek letter names.. if there's a docstring explaining or it's deeply ingrained in the nomenclature of the subject matter then it's ok, I guess
18:04:07
phantomics
I write APL using unicode, also my APL compiler generates Lisp code that includes unicode
18:04:31
phoe
especially regarding the fact that I'm sort of a footnote/Tufte-style sidenote person myself
18:05:29
lotuseater
tfeb: and also matters MUCH having it good readable in handwritten sheets or typeset papers. "is this index i or j?" "is this a zeta or xi?"
18:06:27
lotuseater
lisp123_: when you wanna learn APL phantomics also advised me to the Dyalog Tutor or for use to learn April his long talk on YT
18:07:04
phantomics
The 𝕊 appears in front of most variables in compiled April, it's a reader macro that expands to a form that gets transformed by a macro to intern symbols in the proper workspace package
18:10:16
lotuseater
or from another point of view, in another reality the normal ASCII set could differ. it's like seeing complex numbers not the same as reals, they're just being different operated on but both types are of same "reality"
18:11:00
tfeb
lotuseater: I'm not sure what you're trying to say. written maths is essentially a natural language,and it works pretty well. long names for things would make it radically harder to write, and in in fact read (no-one wants some equation which is already split over three lines to require two pages). (FWIW I write and read more maths than
18:12:20
_death
tfeb: right, I should've been more careful with that remark.. it's a bad habit when you wear the programmer hat.. I do sometimes use the character names when I implement something from a paper.. but often regret it later on if I didn't document what the actual meaning is
18:14:06
phantomics
I always found traditional math notation to be awful, there's no consistency, just a bunch of discordant standards for different things stuck together
18:15:50
_death
tfeb: even in a math paper, there is a balance between greek salad and concise math.. for that I often find papers before say 2000 much clearer than papers written after, at least in the subjects I'm interested in
18:16:24
tfeb
phantomics: exactly. It's a natural language (or a bunch of related ones) and just like English it's an insane mess. Programming languages should not be like mayhs
18:19:00
phantomics
APL strikes a good balance for a programming language that also functions as mathematical notation, I'd rather read math concepts presented in Iverson notation than traditional notation
18:25:12
tfeb
And also, if anyone knows a mail address for Raymond Toy could they either let me know it (not in the channel) or ask me for mine (likewise) and ask him to contact me about series
18:26:25
tfeb
_death: yes, I've mailed that address but last commit was 2013, not sure it is current
18:27:30
tfeb
reason forasking is that I'm trying to make it more installable and don't want to treadon toes
18:29:58
_death
I also wrote some patch for series last year that you may find interesting, though I've not used series in anger :) https://gist.github.com/death/cec04d179e607657f409364442bf2a04
18:34:21
tfeb
and in due course I'd like maybe to remember enough of it (my name is in the commit logs frrom about 1995...) to maybe make real improvements especially for modern implrmentations
18:35:40
tfeb
But I've spent enough of my life pissing other people off that I want to make sure Idon't this time
18:36:46
yitzi
tfeb: rtoy also works on CMUCL and Maxima. He maybe around those repos/mailing lists.
18:45:23
tfeb
I have to go, but if anyone has pointers for series people send a message to tfb, who is me.
20:30:56
Guest82
Hi, sorry for the incredibly late reply (I've had a crazy time in my life lately...) but: Josh_2 contrapunctus shka loke[m] etimmons and beach thank you so much for answering me! on the questions I asked on July 4th! :D Thanks for pointing out at the commercial uses of lisp for web apps and the help dealing with some issue. Cheers!
20:49:49
pl
Maybe worth job change I'll have the time to write some libs for a very commercial lisp use XD
20:59:32
phantomics
since you're back, Guest82: what were those commercial uses? Interested to see...
22:05:58
phoe
is there a portable way to get a type specifier that matches only something of type X and not its subtypes?
22:06:40
phoe
if BAR inherits from FOO, I'd like something that is (AND FOO (NOT BAR)), except obviously I cannot enumerate all subtypes in the NOT because new ones can be created at any time
22:32:21
pjb
the only case is when you can't insert a type between tyep type and NIL. eg (subtypep 'nil '(integer 42 42)) #| --> t ; t |#
22:46:24
moon-child
actually, since in common lisp types can be defined according to arbitrary predicates
22:46:35
Bike
yeah, common lisp types wouldn't work for curry howard so well. they define a naive set theory.
22:47:13
Bike
also, the standard literally defines types to be sets within the context of the language, just to make it clear
22:48:16
Bike
yeah, naive set theory. so things like "barbers that shave only those who do not shave themselves" are sets
22:51:45
Bike
(defun type-that-contains-itself-p (type-specifier) (typep type-specifier type-specifier)) (satisfies type-that-contains-itself-p)
22:52:32
Bike
and then marvel as a math thing from a hundred and twenty years ago leads to the practical consequence of needing to restart your lisp
22:54:47
Bike
e.g., (typep 'cons '(satisfies type-doesnt-contain-itself-p)) => T, (typep '(cons t) ...) => NIL, (typep '(satisfies type-doesnt-contain-itself-p) '(satisfies type-doesnt-contain-itself-p)) => hang