freenode/#lisp - IRC Chatlog
Search
5:28:18
HiRE
hi everyone. I'm getting started in lisp coming from a systems programming background. I am curious how pointers are managed in lisp. I would imagine it would be possible to write a garbage collector in pure lisp but I am not sure how you could manage memory.
5:28:34
HiRE
I thought the mezzano project was very interesting. I'm curious about how lower-level lisp works.
5:29:31
beach
And you can't write a garbage collector in portable Lisp. But you only need tow additional primitives, namely read and write memory at a particular address.
5:30:36
HiRE
ah, so the systems programming stuff would be highly system dependent. If I'm using SBCL on linux would there be read and write available to lisp or would I have to hook into some C or assembly for that?
5:31:16
beach
I would think SBCL has something like that, but you would have to know the low-level details of SBCL in order to use it properly.
5:31:40
HiRE
I'll take a look. I had no idea it would be compiler and system dependent. Very interesting. Thank you
5:32:13
beach
Also, SBCL has a copying garbage collector, so you don't know that a pointer remains valid for very long.
5:33:00
HiRE
Oh ok. Sure. I guess my thought was to use lisp for _everything_ because I really enjoy writing it.
5:33:50
beach
Common Lisp uses what I call "uniform reference semantics", meaning that it works as if you always manipulate a reference (pointer) to an object, and never the object itself.
5:34:34
HiRE
I just learned that reading ANSI common lisp (great book). I used it to write a neat little sieve of erastosthenes that did the stuff in place to save on memory.
5:35:39
beach
Nowadays, classes and generic functions are used quite a lot, and Graham doesn't use those.
5:35:57
minion
HiRE: please look at PCL: pcl-book: "Practical Common Lisp", an introduction to Common Lisp by Peter Seibel, available at http://www.gigamonkeys.com/book/ and in dead-tree form from Apress (as of 11 April 2005).
5:36:37
HiRE
awesome! I had this book in my cart but I snagged a used copy of ansi common lisp for like $7 because it was cheap and it had paul grahams name on it
5:39:01
beach
Peter Seibel, on the other hand, spent a lot of time here, making sure he knew all the conventions.
5:40:01
beach
I don't remember the details of it. I read the book a long time ago. But for one thing, he does not use standard classes and generic functions.
5:41:35
HiRE
ah ok. I haven't learned those yet. By the sounds of it if I keep reading ansi common lisp I'll never learn :P
5:41:48
no-defun-allowed
Yeah, he often uses ckisyres in place of objects and calls them with "messages" comprised of a symbol (in place of, say a generic function) and arguments , which is similar to the object representation in SICP.
5:43:53
HiRE
its kind of funny now that I've drank the koolaid im on the other side of the conversation at work about languages
5:44:15
no-defun-allowed
Yes. In the meantime, you can read the book online, but I've heard some people concentrate much better with dead-tree format.
5:45:11
beach
HiRE: There are some very strong psychological forces that make people resist learning new stuff, even when they are told how much better the new stuff is.
5:45:54
no-defun-allowed
It's probably cliché now, but you can ask them if they complain about spaces between words in a newspaper, or if you can get away with some snide, give them a quiz on operator precedence in their language.
5:47:08
HiRE
you'd think people who enjoy having tabnanny cram style down their throats wouldn't be bothered by some parens :P
5:47:47
stylewarning
HiRE: make sure the thing you ultimately fall in love with isn’t some austere beauty of the language, but rather it’s ability to make you productive at writing code. In other words, write lots of code!
5:47:56
beach
If they are Python programmers, then at least they won't use performance as an argument against Common Lisp.
5:48:57
HiRE
stylewarning: I agree. Im not productive in common lisp yet but it is certainly fun to write. The idea that code can mutate itself and you can basically bolt on your own DSL for _anything_ for free is great.
5:49:35
no-defun-allowed
It's rare to see self-modifying code in (any) Lisp, but code can definitely process other code very easily.
5:50:33
HiRE
where my professor was a lisp fanboy and went on monologues about how its the best language ever made
5:51:06
no-defun-allowed
That is probably how I'm going to get "introduced" to it in formal education, in a year and a bit.
5:51:54
HiRE
maybe not. My class was a very traditional "CS AI" class - prolog and what not were taught as well. Most new universities seem to be trending towards python...gag
5:53:09
no-defun-allowed
We do get Prolog too, and there is quite a lot of symbolic AI as well as the other sorts of AI like state search.
5:53:14
beach
There are some good reasons in favor of Python as a first language, but those reasons are off topic here, so I won't go into detail.
5:53:35
no-defun-allowed
There is also some machine learning—wait, symbolic (as well as "connectionist") machine learning?
5:53:45
stylewarning
The reason universities use Python is because every time they sunset the language, the plethora of textbook authors have something to rewrite. And that’s how you make the big bucks in academia.
5:55:00
no-defun-allowed
And again, there is Norvig's Artificial Intelligence: A Modern Approach, so I think the course can't be too terrible.
5:59:44
HiRE
well I wont tie up the channel any longer in case anyone has anything else. I appreciate the help guys, I'll have to idle here more.
6:02:09
beach
HiRE: There are specific channels for Mezzano and other projects, in case you are interested.
6:43:03
LdBeth
Is there any source on how to use Lisp as a macro assembler/how to design a macro assembler?
6:55:03
beach
LdBeth: I have no information for you, but I am interested in knowing more about your project. I wrote an assembler in Common Lisp, but it is not a macro assembler, and it is quite different from others in that it does not have any surface syntax defined.
6:57:01
beach
For x86-64 (the current target), an interesting problem is that of selecting the appropriate machine instruction for a given desired effect. There are often several instructions that will have the same effect, so there is not a 1-1 mapping between source and machine code.
7:04:04
LdBeth
beach: DEK's MMIX has demonstrated some different instruction that shares the same op code. I have limited knowledge and little interests on AMD64, for that it is a very sophisticated arch.
7:08:22
LdBeth
for example, to run a PPC assembler, I might need to setup a complete MacOS in a emulator first
7:11:04
LdBeth
I wish to write and assemble some "bare metal" program using the native OS I'm currently using, then run them using qemu or something
10:16:40
beach
It would be great if you would acknowledge when you have seen an answer, and even better if you would tell the person giving it whether it was of any help to you.
10:17:32
harovali
beach: I agree. Sorry indeed. Thanks for asking back and yielding the oportunity of apologizing to me.
10:20:03
beach
Having a parameter named X and then funcalling a global function that also happens to be named X.
10:23:34
harovali
I had a reboot session back then , including upgrading to sbcl 2.0.0 , just after you answered, my chat session got closed and later I forgot to come back
10:26:07
pjb
beach: I beg to differ: you can write a garbage collector in conforming Common Lisp. Perhaps not one that garbage its own memory, but one good metalinguistic garbage collector, definitely!
10:28:25
beach
HiRE: Speaking of which, you can't write a low-level garbage collector in conforming C either.
10:29:30
pjb
HiRE: for an example of a GC written in CL, have a look at https://github.com/informatimago/lisp/blob/master/common-lisp/heap/heap.lisp#L1824
10:30:26
aeth
I think the SBCL team stance is that SBCL's GC is C so they can debug it iirc (I can't speak for them directly, I'm just remembering)
10:31:05
beach
I guess if you make all of memory look like a huge array of unsigned bytes, you can write a GC in Common Lisp.
10:31:30
pjb
LdBeth: there are examples… See: https://www.informatimago.com/articles/usenet.html#Compilation
10:32:02
aeth
You can write large parts of a program in non-consing CL, at least in SBCL. The profiling's good enough. So you should be able to write a GC in it. It'd be tricky, I guess. Especially debugging, since the non-consing style usually assumes that it's, well, working.
10:32:02
pjb
HiRE: or a simpler example of GC: https://groups.google.com/forum/#!msg/comp.lang.lisp/Ac-Vj8UJpZ8/s6-kmPmKQIIJ
10:32:56
pjb
LdBeth: since assembler is often used as a HIR for a compiler: https://groups.google.com/forum/#!msg/comp.lang.lisp/QMakibYYZRg/fgQulr5b4BwJ
10:33:03
aeth
What I mean is, yes, your GC program is non-consing (just preallocating what it needs, declaring dynamic-extent most of the rest, and using a special heap data structure that's a huge array), but is e.g. your condition system? Probably not. So once you get an error...
10:33:54
pjb
aeth: If you wanted to do that in a real implementation or system, you would have to define a non-consing subset…
10:34:22
aeth
pjb: You don't have to define a non-consing subset because you can profile SBCL enough just to make sure you accidentally don't introduce consing.
10:34:35
aeth
I mean, I guess you could have your compiler enforce it instead of just relying on the profilers.
10:35:34
pjb
aeth: Yes, like the button astronauts shouldn't press if they wanted to get back to Earth from the Moon… Right.
10:35:37
aeth
But, anyway, that subset does exist and I think it's probably large enough to write a GC in it, if you allow preallocating.
10:36:04
aeth
At least in SBCL. Other implementations might cons more, and seem to be harder to check.
10:38:04
aeth
Non-consing is not as hard as it seems because it's not really non-consing, it's cons-up-front, and then use dynamic-extent for the rare rest.
10:38:20
pjb
aeth: https://www.smithsonianmag.com/smithsonian-institution/margaret-hamilton-led-nasa-software-team-landed-astronauts-moon-180971575/
10:41:09
no-defun-allowed
"The astronauts had access to only 72 kilobytes of computer memory (a 64-gigabyte cell phone today carries almost a million times more storage space)." Conflating primary and secondary memory (where such a barrier does exist due to software limitations) is always a sign the author is proficient in writing about computers.
10:52:45
harovali
https://pastebin.com/iKxDh2Sc if you wanna see my code. For some reaseon beyond my understanding and my research abilities, the funcalls (especially the first one , in line 72 ) fail miserably with the error ' evaluation stopped on nil'
10:54:18
no-defun-allowed
You would probably also be better served by a class instead of a set of six closures that represent a state.
10:55:09
no-defun-allowed
Then I'm not sure how much I can suggest without a backtrace to see how you got there.
13:25:48
|3b|
are there any "best practices" for compiling a set of code a few times, with different package each time? if i just put the file in the .asd 3 times, it will get the same .fasl each time, which won't work
13:27:06
|3b|
ACTION 's ideas so far are: convince asdf to change the .fasl name for each instance. "include" the code file into 3 separate wrapper file that set the package etc. write some ugly defining macros to duplicate the definitions with package prefixes
13:30:22
|3b|
end-goal is to implement some code once and have versions specialized on single-float, double-float, or real. user code would then specify which it wants with package local nicknames
13:56:54
|3b|
or if it is unsigned-byte 8 array, maybe use nibbles to copy 4 or 8 bytes at a time, depending on length and alignment
14:03:36
|3b|
if you can use static-vectors to avoid copying at all, that might be better, though it requires manual memory management which makes it annoying for some things
14:04:10
|3b|
ACTION usually does element-by-element copies for lisp->foreign though, if static-vectors isn't applicable
14:05:33
asdf_asdf_asdf
Hi. I do C-M-s and typed regex. It marked words. How changing marked to "selection", that able copy more than one marked words?
14:06:18
varjag
this is is in my alsa code… worked fine on faster systems, but on an arm target beginning to get underruns with sample rates at 32k+
14:08:16
|3b|
might see if ccl has some way to get a pointer to the vector data, and call memcpy or similar on it
14:08:53
|3b|
(wrapping it in some portability thing that copies if it has to, if you care about other implementations)
14:10:25
|3b|
or just use cffi:with-pointer-to-vector-data, but then you might pay double copy cost on implementations that don't have a way to get a pointer
14:13:12
|3b|
looks like there is also a make-shareable-byte-vector you should use with it for complete portability, but the extra copy on some implementations usually means i don't want full portability when i use it anyway
14:13:49
varjag
we're moving to lispworks for prod but would really like to sort it out with ccl first
14:14:26
|3b|
looks like lispworks might want make-shareable-byte-vector for use with with-pointer-to-vector-data
14:16:48
_death
for sbcl I implemented (a POC) mmaped memory as lisp arrays, so you can use shared memory naturally
14:17:58
|3b|
looks like cffi uses http://www.lispworks.com/documentation/lw71/FLI/html/fli-122.htm on lw, which wants special allocation
14:21:23
|3b|
sbcl and ccl can apparently get pointers to any vector, so it just makes a normal array
14:26:36
beach
I am looking at the LispWorks manual, specifically the section about the debugger. It looks to me like the LispWorks debugger is no more sophisticated than the one in SBCL/SLIME. Am I right? In particular, I don't see a way to set a breakpoint before a program is started. Can anyone who has used LispWorks confirm this interpretation of mine?
14:27:27
Xach
beach: I don't know, but I do know that the lisp-hug mailing list is always very helpful.
14:45:43
p_l
beach: also macro tracing (this switches code to evaluator instead of compiled, afaik) and working Who Calls database
14:47:24
beach
I am mostly interested in breakpoints and how they work. Specifically if you can set a breakpoint in system code, like CONS or POSITION.
14:54:48
p_l
(can't test right now, as personal edition no longer works on mac, and I'm too lazy to take a trip for the other laptop)
14:55:06
p_l
beach: it's hooked into "dspec system" according to http://www.lispworks.com/documentation/lw70/IDE-W/html/ide-w-207.htm
14:55:56
p_l
http://www.lispworks.com/documentation/lw70/LW/html/lw-39.htm#41682 <-- this is dspec docs
15:09:22
pjb
|3b|: I would have different files that would each define the current package, and include the common file (eg. with com.informatimago.common-lisp.cesarum.utility:include-file).
15:17:11
pjb
beach: the way break points work depends on the level of the code you're trying to suspend. You can have breakpoints at the source level (eg. inserting (break) forms. You can have breakpoints at the microcode level, either by live-patching the instructions, replacing them by a jump or a software interrupt, a trap, or even an invalid instruction if you can handle it and resume, or by stepping all the execution setting a flag to do
15:18:07
pjb
You could also set break points by configuring the MMU to prevent access to the specfied instructions.
15:19:40
pjb
Working at the source level can be easier: you directly know where the break point occurs, while if you break (or step) low level instructions you have to map their addresses to source expressions (which may be difficult or impossible, depending on the compiler optimizations)
15:20:35
pjb
Indeed, since modifying the code has its difficulties. It may be complicated to do or even prevented by the system…
15:21:25
p_l
or simply you might not want to deal with the trouble of arranging possibly complex jump chain to get the original instruction continued
15:22:02
p_l
debug registers let you create a hw breakpoint that has separate configuration from what application might have used for itself
15:23:07
pjb
One easy way to do it, is to "instrument" the code. It's easy to do at the compilation level (eg. with high debug level). You just insert the instructions needed to step/break.
15:24:21
pjb
You don't need support from the system or the processor, it can work portably and conformingly, and it can give very good results source-wise. The only problem is that the instrumentation changes the generated code, so bugs may appear or disappear when you do that… (should not be a problem if the compiler is bug free!).
15:30:02
beach
pjb: I am specifically interested in the mechanism used by LispWorks. But I see now that breakpoints are part of the stepper, so that should give me some hints.
15:35:29
splittist
one day I will remember the correct order of arguments to get-hash. Today is not that day.
15:37:02
jackdaniel
splittist: you may arrange it as English sequence: "get eggs from the store" is more natural than "get from the store eggs"
15:45:34
p_l
beach: given the list of places that a breakpoint can be declared, I'd say there's good chance that they replace call sequence