freenode/#lisp - IRC Chatlog
Search
22:29:22
jackdaniel
LdBeth: while anlsh is excused as a newcomer for not knowing the channel topic you are not, please stick to it
22:34:21
anlsh
LdBeth: Drop me a heads-up in here if/once you send your first pm, I'm running erc right now and don't think it's functioning entirely correctly
23:41:06
jcowan
the loop syntax is LOOP WITH var = value AND var = value etc. (assignments not bindings) FOR (headvar . tailvar) IN list DO expr)
23:43:20
easye
lukego: sbcl20 is certainly doable for whatever time you have available. We start on Sunday night.
23:57:33
jcowan
the code is very interesting, but there was an explicit warning "adapt the loop to your Lisp: Maclisp, Interlisp, etc."
23:58:06
jcowan
I mean what the code does is interesting: a two-page Prolog interpreter using downward success continuations (recursions) instead of the usual upward failure (streams)
0:00:36
no-defun-allowed
(And I recall in a SICP video, Sussman stated he thought implementing logic programming with streams was simpler than with continuations.)
0:02:01
no-defun-allowed
Josh_2: Anything that's a specifier for a name (which I must check the correct term for), i.e. any string or symbol.
0:10:40
jcowan
But on the good side, the Nilsson article is there at https://github.com/rm-hull/ambages/blob/master/doc/twspi.pdf
0:11:19
jcowan
on the bad side, there are typos in the code; it obviously was retyped by someone who couldn't count parens
0:16:32
easye
ACTION is kinda reminded about the similarity to the shape of "correct" sexpr to that of a pattern in Go that will "live".
0:16:35
Josh_2
I defined a package, exported some symbols and then used that package in another but I have to refer to the functions within that package with a double colon.. <package>::<function> I was hoping the symbols would simply be imported and I could refer to them simply as (<function>) what have I oofed?
0:35:45
pjb
LdBeth: once I found a bug for a single wrong pixel on the screen (true stories, it was in 1986, the screens had only (* 512 348) #| --> 178176 |# pixels! ;-)).
0:37:30
jcowan
LdBeth: I messed with this program a few decades ago and a friend and I carefully counted the parens and figured out which ones to insert/delete. Unfortunately I lost the hard copy on which I did that.
0:38:11
jcowan
Lispers *with emacs* are magical beings etc. etc. Lispers without emacs, like me, have to recite "end of this, end of that" as we go. Not too hard really
0:40:07
LdBeth
jcowan: yeah that’s what I thought, figuring out parentheses printed on paper is not easy to me
0:42:19
Josh_2
clothespin: I am in the second package in the repl and I have to refer to my previous packages functions with <package>::<func> even though I have them in the :export clause of (defpackage )
0:43:52
clothespin
some lisps get buggy when redefining packages, try (symbol-package 'my-symbol) for debugging
0:49:47
clothespin
if you intern the symbol in the second package before putting it in your :use it could act like that
0:52:43
pjb
clothespin: you may want to use (com.informatimago.tools.symbols:check-duplicate-symbols)
0:54:46
clothespin
i usually restart sbcl as well but for the record i rarely had to do that with allegeocl
4:54:52
no-defun-allowed
Though elisp macros and CL macros are fairly similar, so it still might make sense in a CL context.
5:04:05
parisienne
yeah, the question I have is kind of generic and related to the appropriate use of macros. Not really about Emacs. Didn't want to risk a kick. What is ##lisp?
5:05:40
pjb
parisienne: have a look at: Casting Spels in Lisp Conrad Barski, M.D. http://www.lisperati.com/casting.html
5:06:23
beach
parisienne: Go ahead and ask. You will be told if your question is not appropriate for this channel.
5:15:45
parisienne
Well, I have been writing elisp, clojure and some CL for quite a bit now. Never touched macros, because most of the time functions just did what I wanted. Now to grasp macros better I am using my elisp config and trying to find things I can replace with macros. In this specific case I wanted to define a symbol/variable and set it to a value based on a file it reads at "compile" time. Here is the pastebin:
5:15:49
parisienne
I wanted to end up with either a (setq somevar "somevalue") or if the file doesn't exists, it should be (setq some-var nil).
5:16:53
pjb
parisienne: what would happen if the setq-if-exists form is evaluated without being compiled?
5:19:00
pjb
parisienne: so your question is quite emacs specific. In emacs lisp, like in CL, variables should be declared first. Using setq works, but since emacs 25 there is lexical bindings, so it is very preferable to define variables with defvar… (and of course, also use setq, since emacs lisp doesn't have defparameter, unless you define such a macro).
5:19:53
parisienne
the idea was just to have whatever symbol I define to nil. Still not sure about evaluation/compilation process in all the lisps. That is why I wanted to ask here. You can throw a CL example at me if you have anything.
5:22:21
parisienne
specification is basically, I pass in a symbol -> it should generate a "global" variable that gets a value from something else (in this case a file).
5:23:08
pjb
You say compile-time, but you only do things at macro-expansion time. And you don't say what happens at run-time.
5:24:27
parisienne
at the moment I just call the setq-if-exists in a function and after the call I use the passed in symbol in something else.
5:25:48
parisienne
Didn't think about that. But in my mind it should just override whatever value is/was there.
5:31:28
pjb
Well, it's rare to be wanting to load in a variable data at compilation-time. Configuration is something that is more often left for run-time and the end-user or administrator.
5:32:13
pjb
Compilation is usually completed long before the software is installed, on a different computer, by different people, than those who will install it, or use it.
5:33:17
pjb
While it's possible in lisp to inline data, when we save the program as an executable image, usually programs are distributed with resource files to be installed in specific places on the target system, and loaded at run-time.
5:36:43
parisienne
well, the idea for this started when I was writing a REST library in Clojure. What I wanted was to read all the endpoints definitions from a file and generate some base functions at compile time. I would have attempted the same thing in CL. Not sure if my reasoning makes any sense.
5:44:38
pjb
parisienne: when you have something like this, you actually have code in this file. There's no point in using a different system to load this code and compile it than normal lisp code.
5:44:50
pjb
parisienne: instead, write a macro to interpret this code, and put it directly in your sources!
5:46:32
pjb
I assume you have a function such as (generate (parse *data-read-at-compilation-time*)) Then you can write: (defmacro define-endpoints (&rest endpoints-definitions) `(generate (parse endpoint-definitions))) ; parsing will be simplier, since the lisp reader will have already tokenized it.
5:49:20
parisienne
pjb: yeah, exactly! This was exactly what I planned to do. But I didn't feel confident doing that yet.
5:50:23
pjb
Note the macro cannot be simplier. So you can gain confidence easily, by testing and debugging the parser and the generator independently.
5:50:54
pjb
(generate '((some definition) (and some other))) -> (progn (defclass …) (defmethod …) …)
5:53:15
parisienne
pjb: exactly. But you got my point and I assume it would not be unusual to see something like that in a library, correct?
6:21:07
montxero
I have a question, is it possible to construct an a-list where the cdr is a proper list?
6:28:49
pjb
montxero: (let ((attributes '())) (acons 'colors '(red blue white) attributes)) #| --> ((colors red blue white)) |# seems possible…
6:37:16
pjb
It's only the printed representation. Since there are no list and no a-list in lisp (paradox!), you need to interpret the bunch of cons cells as you wish.
6:37:40
pjb
When you consider a-lists, ((colors red blue white)) is interpreted as ((colors . (red blue white))).
6:37:55
beach
montxero: Maybe there is something I don't understand, but the CDR of an alist is always a proper list.
6:39:19
beach
My brain is too small to interpret what people utter in a way that contradicts what they actually did utter.
6:40:50
pjb
There's not much difference between an association and a property, it's just how they're represented: plist: (k1 v1 k2 v2 … kn vn) alist: ((k1 . v1) (k2 . v2) … (kn . vn)).
6:42:03
pjb
Furthermore, alist (the CL functions working with a-lists) can use keys of any class (there's a :test argument to use the equality you want), while plist (the CL functions working with p-lists) use only symbols (normally) and always use EQL to compare the keys).
6:44:26
pjb
fengshaun: note that both a-list and p-lists use the same number of cons cells, and are as efficient one as the other.
6:45:10
aeth
Scheme uses alists because they usually don't have a plist equivalent, and definitely don't portably. In CL, plists tend to be more common than alists.
6:46:15
aeth
The main disadvantage of plists is that you can't use map/mapcar, but you can loop by #'cddr and use a few other things
6:46:36
aeth
The main advantage of plists is that you can use &key in destructuring-bind, essentially treating plists like keyword arguments.
6:47:07
pjb
Well, you need more parentheses to write a-lists. But there's less risk of desynchronisation with a-lists than p-lists. If you miss two keys or values in a p-list, you can mix it almost entirely: (k1 k2 v2 k3 v3 k4 v4 v5) vs. ((k1) (k2 . v2) (k3 . v3) (k4 . v4) (nil . v5))
6:53:24
aeth
That can get confusing when the key and value are of the same type, usually a keyword in that case. It's the same issue with function calling with keyword arguments. You're basically requiring newlines for clarity at that point.
6:54:07
aeth
On the other hand, plists mirror keyword arguments so closely (see my previous two lines) so that's probably why they're more common than alists
6:56:50
montxero
beach: nice play the cdr of an a-list is always a proper list. I meant the cdr of an element of an alist
7:12:41
Cymew
aeth: Are you sure plists are more common? I find alists are mentioned so often as a suggested solution. I actually struggled to find a plist when I needed an example.
7:14:39
pjb
a-list might be more common, because you can map other types than symbols (or other EQL-able objects).
7:15:13
pjb
(cdr (assoc "hello" '(("HELLO" . "SALUT") ("BYE" . "AU REVOIR")) :test 'string-equal)) #| --> "SALUT" |#
7:18:14
Cymew
Shinmera: Huh. That is propably making them more common. I wonder how often they are used intentionally, though, rather than that indirect manner. Like pjb say, alists have some flexibility.
7:20:41
aeth
Cymew: only someone who has all of Quicklisp installed can know for sure, but unlike most things, this would be pretty hard to search. Effectively impossible to get exact numbers on because so many macros implicitly would use plists/alists/etc.
7:21:18
aeth
any destructuring-bind with &key in a macro is using a plist tail at the very least, if not a full plist
7:22:46
Cymew
I'm learning more about implementing lisp cores than I expected. I have never given plists much thought before. I have been enlightened.
7:36:09
pjb
And of course, it was an essential implementation data structure, since symbol themselves were implemented as a plist (we still have symbol-plist, but the symbol name, the function slot, the value slot, and others were stored on the symbol plist in LISP 1.5).
7:56:19
p_l
hmmm. Separate the values from identity, so symbols in different environments are still EQ?
7:58:19
beach
The trick was to make function calls fast, i.e. to avoid doing a hash-table lookup for each call of the form (f ...).
8:00:14
beach
The static environment of a function contains disembodied function cells (in the form of CONS cells) containing the function object.
8:01:26
beach
But this way, I will be able to isolate implementation code from user code, for better safety. And I'll be able to do sandboxing a bit easier.
8:03:45
beach
This feature can also be used to separate the compilation environment from the run-time environment.
8:07:29
beach
Anyway, I'll add "symbols have function cells" to a list of misconceptions along with "Lisp is interpreted".
8:08:22
p_l
beach: well, symbols being structures are implementation detail, what matters I guess is that there's "illusion" of symbols having a set of standard "slots" of information
8:09:27
beach
p_l: It is better seen as just another protocol. Once one realizes that, then there is more freedom of choice with implementation.
8:09:55
beach
p_l: Maybe so. All I could find in the literature was Scheme environments with hash-table lookups for each function call.
8:10:36
p_l
beach: that sounds like very inefficient implementation for language that explicitly pushed lexical environments
8:13:09
ggole
Why would fetching the function stored in a symbol require a table lookup? Wouldn't the code for (f ...) load the function from the symbol for f (which is looked up at read time)?
8:15:20
p_l
if you push max perf, you can even remove the indirection without disabling redefinition, at the cost of making redefinitions slow (but possibly enabling safe redefinition of inlined functions)
8:19:36
beach
ggole: It can't be redefined by changing the field of a symbol if the goal is to have different environments that allow different values for the property.
10:05:54
specbot
Tilde E: Exponential Floating-Point: http://www.lispworks.com/reference/HyperSpec/Body/22_ccb.htm
10:05:58
phoe
> If the parameter d is omitted, then there is no constraint on the number of digits to appear. A value is chosen for d in such a way that as many digits as possible may be printed subject to the width constraint imposed by the parameter w, the constraint of the scale factor k, and the constraint that no trailing zero digits may appear in the fraction, except that if the fraction to be printed is zero then a
10:06:22
phoe
If I am reading this correctly, then "if the fraction to be printed is zero then a single zero digit should appear after the decimal point" applies in this case.
10:07:33
phoe
K is defaulted to one and therefore positive, so we should print one decimal digit after the decimal point.
10:10:25
pjb
phoe: there's one constraint that must be respected, when k is absent, it defaults to 1, and the constraint is k<d+2 ; since d is absent, any value of d is possible, such as k<d+2, ie. 1<d+2 ie.-1<d ie. 0<=d ie. any value is possible, such as the number can be printed.
10:11:34
phoe
pjb: in this case, we may choose any value of D that lets us accurately print the number. Most implementation choose the minimum required number of digits.
10:12:41
pjb
1.e+0 is valid reader syntax for a floating point number, so I guess it can be printed as such (contrarily to my expectation).
10:14:17
phoe
However my question is about "except that if the fraction to be printed is zero then a single zero digit should appear after the decimal point.".
10:14:59
pjb
oops, I missed the except. Yes, it clearly indicates that it should be printed as 1.0e+0
10:15:49
phoe
"If k is positive, then it must be strictly less than d+2; k significant digits are printed before the decimal point, and d-k+1 digits are printed after the decimal point."
10:16:25
pjb
and d being absent, you can choose any convenient value, but subject to the following constraints, including the except.
10:18:10
pjb
But since it must also be at least 1 to print the 0 when it's 1.0, then we have (and (<= 0 d) (<= 1 d)) <=> (<= 1 d).
10:18:46
phoe
This implies that an implementation may want to print 1, 2, 5, or MOST-POSITIVE-FIXNUM zeroes, and all of these are correct.
10:21:00
phoe
So if the fraction to print is zero, we must print at least one zero to satisfy the part about "if the fraction to print is zero" and at most one zero to satisfy the "no multiple trailing zeroes" rule.
10:21:24
phoe
And this implies that "1.0e+0" is the correct way to go, which in turn clashes with the body of the ANSI-TEST.
10:22:04
phoe
Which still doesn't make sense. I need to figure out the rationale that this test follows, since it is possible that this clashes with our understanding so far.
10:25:34
phoe
So is mine, but ansi-test should be consistent with the spec. That is why I ask a question - the way I read it, this test is not correct, so either that test is not correct, or I am not reading something correctly.