freenode/#lisp - IRC Chatlog
Search
2:06:29
pransninja
So far I love the whole idea of "live" programming with a REPL along with your text editor.
2:07:10
pransninja
I am already worried how bad going back to my "everyday" language would feel like. lol
2:07:45
fiddlerwoaroof
Yeah, I find CL so much nicer than other environments: and very few other programming languages have a similar experience: of the popular ones, only Clojure comes close and it's a bit annoying in some respects.
2:10:41
pransninja
fiddlerwoaroof: I am on learn languages journey, after finishing PCL I will finish Real World OCaml, then learn F# maybe, or possibly Clojure.
2:11:38
fiddlerwoaroof
Yeah, I've finished that journey :), I think I'd suggest Haskell rather than ocaml, but this is getting off-topic;
2:11:51
_death
the "mainstream" CL environment is still a long way from satisfactory in many ways.. there are lessons from emacs, jupyter, R, matlab.. but that requires a ton of work, and we're all busy doing Something Else(TM)
2:13:04
fiddlerwoaroof
Yeah, beach and froggey sometimes seem like the only people doing something about that.
2:13:35
fiddlerwoaroof
I've wanted to, but it doesn't really pay the bills, and I don't have much free time :(
2:16:22
pransninja
fiddlerwoaroof: I like the idea of Haskell, trust me it is on my list of to learn languages, but probably right before I want to learn Rust properly.'
2:17:21
pransninja
fiddlerwoaroof: I want to learn OCaml becuase I think ReasonML is going to be big in my industry.
2:17:49
pransninja
_death: Sure, but I can say with utmost certainty that reading a book is part of learning a language.
2:19:37
fiddlerwoaroof
It's often better to have some moderately complicated project to do in each language you learn and then use books and other materials to help you to implement your project in the language
2:20:14
fiddlerwoaroof
I learned CL by reading like 2/3rds of PCL and then trying to implement a RSS reader in CL
2:20:58
pransninja
fiddlerwoaroof: For sure, I have some ideas in my mind, I actually have a project in back of my mind for years that requires understanding multiple languages to execute it well, along with a solid understanding of type theory.
2:21:21
pransninja
But back to lisp, given things like `(with-open-file (out filename ....))` how do I differentiate a function call from a list passed as a parameter?
2:21:46
fiddlerwoaroof
You can't in the general case: a macro determines the semantics of its arguments
2:23:28
fiddlerwoaroof
Generally, there are two or three common macro patterns: with-* define-*/def* and do* and, within each pattern, the arguments are treated in fairly consistent ways.
2:24:12
_death
you always need the context... (+ 3 5) may look like a function call, but it's not, because surrounding that form is (quote ...)
2:26:25
pjb
The context is not only the surronding form, when you read it, it's the *readtable*, the *package* and other *read-…* variales.
2:28:00
pjb
(defun x ()) (list (quote x) (function x)) #| --> (x #<Compiled-function x #x302002FFC72F>) |#
2:31:27
pjb
Some other functions are named with lists of 2 symbols, the first being CL:SETF, and some functions are unnamed.
2:31:47
pransninja
What I want to understand is that if `(+ 1 2) is not a function call, then what it is?
2:32:38
pransninja
What does " Declared type: (FUNCTION (&REST NUMBER) (VALUES NUMBER &OPTIONAL))" means?
2:33:02
pjb
It's the type of a function that takes 0 or more numbers and returns a number and perhaps something else.
2:35:58
_death
pransninja: and what `(+ 1 2)` is depends on the context.. it can be a function call, or it can be a list of 3 elements, or it can be the textual description of such a structure, for example..
2:37:55
pjb
pransninja: (+ 1 2) is a sequence of character. This is represented as a string in lisp, and a string is represented with the sequence of characters "(+ 1 2)" `(+ 1 2)` doesn't represent anything in lisp. More precisely, it is read as `(+ 1 2) and ` the later being incomplete and provoking an end-of-file error
2:38:00
pransninja
Given the flexibility of lisp and the fact that is uber-meta, anything could be anything?
2:38:26
pjb
"(+ 1 2)" is a string, it is also a sexp. It is read as the sexp (+ 1 2) : (read-from-string "(+ 1 2)") #| --> (+ 1 2) ; 7 |#
2:38:53
pransninja
But I suspect like how overloading could be abused in C++, it is likewise froward upon in Lisp to redefine "common sense" semantics?
2:38:58
pjb
Then the sexp (+ 1 2) can be processed by various functions. When it is processed by EVAL, it is interpreted as a function call: (eval '(+ 1 2)) #| --> 3 |#
2:39:26
pjb
But if it is present in the context of other sexps, it can be interpreted differently: (eval '(quote (+ 1 2))) #| --> (+ 1 2) |#
2:41:43
pjb
(defpackage "ADD" (:use "CL") (:shadow "+")) (defun add::+ (&rest args) `'(let us add ,@args and have fun)) (let ((*package* (find-package "ADD"))) (eval (read-from-string "(+ 1 2)"))) #| --> '(let us add 1 2 and have fun) |#
2:45:23
pjb
pransninja: (setf *read-base* 2.) (let (+ 3 4) (setf + 1 3 1 4 1) (+ + 3 4)) #| --> 3 |#
2:46:02
pjb
In that context, + is just a symbol, and is interpreted by the macro LET as the name of a variable. (3 and 4 too, since the current read base is two).
2:46:54
pjb
But notice that in (+ + 3 4) the first occurence of the symbol + is interpreted as the name of the function +, while the second occurence is interpreted as the name of the variable + bound by the surrounding LET form.
2:47:28
_death
+ is also a fixed-point function when used in the repl... to see that, type + RET a few times and see how it converges
2:48:14
pjb
That's because it's defined to be a special variable that is bound to the last form that is evaluated in the REPL.
2:50:43
parjanya
is there a way to mark if I want a symbol to be interpreted either as a variable or a function?
2:54:18
pjb
parjanya: it's based on the syntax. In the first position of an applicative list, it's interpreted as the name of an operator (function, macro or special operator). In other positions, as the name of a variable (or depending on the macro or special operator).
2:54:28
parjanya
I mean, if I (defun a-test (lalala) lalala) and (defparameter a-test "a string") and do (a-test a-test)
2:54:56
pjb
And then of course, as mentionned by _death, there are symbol macros, but also reader macros that can distort your senses.
2:55:16
parjanya
if I do (a-test a-test) the first one will be the function, the other one the variable, but I wonder if there is a way to say that explicitly, like when one uses 'a-test to just get the symbol
2:56:02
_death
you can use the FUNCTION operator to designate a function.. (function +) ... a shorthand for this operator is the reader macro #' .. so #'+ will also work
2:56:36
pjb
parjanya: not really in general. In the case of global special variables, you can get the value with (symbol-value 'a-test) and for global functions, you can get it with (symbol-function 'a-test), so in that specific case, (a-test a-test) can be replaced by (funcall (symbol-function 'a-test) (symbol-value 'a-test))
3:03:42
fiddlerwoaroof
Lisp, for me, was eye-opening because it disabused me of two things: (1) compiled languages need to be statically typed and (2) compiled languages have to have a slow feedback loop.
3:04:27
fiddlerwoaroof
It was also very satisfying to find a language where I could actually write concurrent programs, since most of the other languages I've used have some form of GIL to make one's life difficutl
3:06:07
beach
fiddlerwoaroof: And it is a bad idea to pretend there is, because it gives people the wrong idea.
3:06:37
beach
fiddlerwoaroof: Then they will think like this: Lisp => interactive => interpreted => slow.
3:07:43
beach
fiddlerwoaroof: It is very important to let people (especially your typical ignorant programmers) that most modern Common Lisp systems compile on the fly, so that the resulting speed is comparable to that of compiled C.
3:08:43
fiddlerwoaroof
and then I recompile the function with (declare (speed 3) (safety 0)) and show the difference in the disassembly
3:08:53
beach
Those ignorant programmers will of course always have an excuse to stay away from Common Lisp, but making sure they understand this issue gives them one fewer reasons to do so.
3:09:28
_death
you can also mention printf vs. FORMAT, and C's lack of compiler macros and of FORMATTER :)
3:10:50
fiddlerwoaroof
Also, emacs macrostep expander is pretty cool when people complain about debugging macros
3:11:13
pransninja
beach: Compile on the fly is called JIT and it is not exactly on par with native code.
3:12:06
fiddlerwoaroof
Common Lisp implementations generally have a compiler that turns your lisp code into machine code
3:13:05
_death
pransninja: you can also compile things on the fly, the language is available at all times..
3:13:13
beach
pransninja: Perhaps you are one of those programmers I referred to who think that interactive implies interpreted.
3:13:24
fiddlerwoaroof
So it's "on the fly", but not in the way a tracing JIT compiles on the fly: e.g. it doesn't take execution patterns into account to determine the compilation
3:13:31
loke
pransninja: It means "automatically when needed". As opposed to the user having to go through a manual compilation phase.
3:14:15
beach
pransninja: It means that between the time you validate an input expression and the time you see the result of executing it, the Common Lisp system has turned it into real native code.
3:15:42
beach
pransninja: It means that between the time you validate an input expression and the time you see the result of executing it, the Common Lisp system has turned it into real native code.
3:16:03
_death
pransninja: (let ((code (progn (print "Enter code: ") (read)))) (disassemble (compile nil `(lambda () ,code))))
3:16:15
pransninja
And how is that different than "offline compiling"? in contrast to your "on the fly"?
3:17:53
pransninja
Look, I think REPL is sexy, I am loving it, this is my first experience with such a "live" coding way.
3:18:10
pransninja
I have used REPLs before, but this level of integration with text editor and such is dope.
3:18:10
Bike
using a repl is a different way to program from writing a program and throwing it at gcc or whatever, as you've already seen
3:18:16
beach
pransninja: Most people think of compilation as a batch compiler producing files containing object code that then has to be linked in order to produce an executable. I use "on the fly" as a contrast to that.
3:19:09
beach
pransninja: I am more interested in why you think the Common Lisp compiler produces something that is not "on par" with native code. Can you elaborate on that?
3:19:11
loke
pransninja: As I said earlier, "on the fly" means that it's done automagically, without you having to go through a compilation phase (like in C, when you have to run "make" separately before testing the program)
3:20:03
pransninja
beach: The common meaning of "on the fly" is JIT, which is on par with native code, but not quite.
3:20:49
beach
pransninja: Maybe you have a different concept of "native code" that most people here do.
3:21:02
loke
pransninja: Actually, JIT can (and has been shown to) produce more efficient code than static compilation. That said, most Common Lisp implementations does not use a JIT (only ABCL does, as far as I know)
3:21:06
beach
pransninja: That is why what the Common Lisp compiler does is not JIT as you were told.
3:21:09
pransninja
In contrast to "offline" compiling where you just have native program, and maybe a runtime, and you CPU just deals with that.
3:22:01
loke
pransninja: True. But it's mostly irrelavent in the discussion of Common Lisp, since most CL's does not use a JIT anyway.
3:23:22
loke
pransninja: OK, type the following into the REPL: (defun foo (x) (declare (optimize (speed 3) (safety 0))) (1+ x))
3:24:27
pransninja
loke: Yeah, so I got to run disassemble with my text editor, I see the disassemble.
3:25:21
parjanya
what’s difficult about "on the fly" meaning "without having to invoke make and then execute"?
3:25:29
pransninja
Many IDEs allows you to do see "disassembly" or even "run" compiled languages with "invoking compile" directly.
3:26:00
loke
pransninja: Indeede. But none (or at least very few) of those languages allow you to recompile code _while_the_program_is_running_
3:26:19
beach
There is no such thing as a "compiled language". That has to do with the implementation strategy.
3:27:02
pransninja
beach: Yeah, which is why I said "the language is compiled" not that "you're using a compiled language".
3:27:44
pransninja
Searching for "on the fly compiler" and see what your fav' search engine brings up: Just-in-time Compiling.
3:28:40
fiddlerwoaroof
pransninja: languages aren't compiled. Almost any language can be implemented by a compiler or an interpreter
3:29:20
_death
pransninja: here is a program: (defvar *program* '(lambda (x) (1+ x))) .. it is not yet compiled
3:29:22
loke
pransninja: You're arguing sematics now. You have some very specific definitions of certain words that does not exactly match the definitions everybody else is using. Now, you may think that our definitions are wrong, but that doesn't matter. I think you have a rough uinderstanding of the way Lisp does things, and it doesn't matter what you or I call it, no?
3:30:06
_death
pransninja: now we have arrived at the moment to compile it, so we compile it, just in time: (compile nil *program*) and call it (funcall * 123)
3:31:17
pransninja
_death: It doesn't matter what. On The Fly Compile is a synonym for JIT, and JIT is basically dynamic translation, if you're not doing dynamic translation, you're not compiling on the fly.
3:31:53
loke
pransninja: We need to call it SOMETHING, and if you're not happy with our definition, what do you suggest instead?
3:32:18
pransninja
_death: I said, search for "on fly compiler" in whatever search engine you like and see what the first result is. If it is not JIT, I will eat my banana.
3:32:41
parjanya
the funny thing is you decreeing the meaning of an expression and saying that we shouldn’t argue semantics ; )
3:33:36
pransninja
I am not decreeing, I have read "on fly compile" refereed JIT that I struggle to see how anyone would think it could mean anything else. :P
3:33:46
loke
pransninja: No. The REPL means read-eval-print-loop. It's just the commandline interface. Even fully interpreted implementations have a REPL.
3:34:10
loke
pransninja: The first non-Java-related hit for on-the-fyl compilation was this article: https://blogs.msdn.microsoft.com/abhinaba/2006/02/09/c-writing-extendable-applications-using-on-the-fly-compilation/
3:35:05
loke
pransninja: That artcile discusses calling the C# compiler dynamically, in a way that is not too disimilar from the Common Lisp way of doing it.
3:35:38
fiddlerwoaroof
"on the fly" is sort of a colloquialism, so one generally figures out what it means by looking at the context it's used in, not by forcing a certain meaning onto the phrase wherever you find it.
3:36:11
pjb
A compiler may still involve a byte-code interpreter or some other form of interpreting for execution.
3:37:42
pransninja
loke: I somehow feel like "Just-in-time compilation" Article on wikipedia is also not "Java" related.
3:37:43
_death
pransninja: but you're a programmer! so we can resolve the ambiguity using code.. so please, tell us what you mean using code
3:37:55
fiddlerwoaroof
Common Lisp implementations will often call the compiler "automatically" when trying to evaluate a chunk of code and, on the fly is a reasonable way of talking about this. In a JIT, the compiler is called at runtime in response to observed patterns of execution, which is another thing to reasonably call "on the fly" compilation.
3:38:49
loke
pransninja: But this all very “whatever” since you have made your point clear, and while we don't agree with you, I think we understand what you mean.
3:40:18
loke
pransninja: Perhaps after using Lisp for a while, you can start to understand why we feel it's important to make these distinctions. Even if you refuse to use our terminology, it will help you explain things to us.
3:40:54
pransninja
Look, my first comment after asking a question when I got here was that I love this whole "live" programming with a REPL + editor setup.
3:41:25
pransninja
I even expressed my concerns about how my everyday programming language envs would feel like after this.
3:42:03
pransninja
But there is no point in repeating that "on the fly" means JIT pretty much just about anywhere I have read it.
3:42:07
loke
pransninja: All right. So let's just drop the terminology discussion, and focus on the important points: How to ensure that you feel confortable with Lisp.
3:42:43
loke
pransninja: I wouldn't say Lispers have a very “different” definition. More nuanced perhaps.
3:43:57
loke
pransninja: And if you want to twist your head even further, remember that ABCL is an implementation of Common Lisp whose compiler generates Java bytecodes, at runtime.
3:44:07
aeth
"on the fly" can be used to implement JIT, right? Is it possible that a language that compiles to CL could be JIT even when the implementation itself is AOT? Or do CL implementations not have enough introspection?
3:45:22
loke
pransninja: So as you can see, at that point it simply doesn't make sense to even talk about the distinction, because ABCL is pretty much “all of the above”.
3:46:51
whoman
for each dictionary entry linking to other entries, forever. how do we even resolve that macro ?
4:01:50
pjb
(defun eval (expr) (funcall (coerce `(lambda () ,expr) 'function))) is a valid CL:EVAL implementation.
4:02:27
pjb
Notice it doesn't imply compilation. Coercing to the type function doesn't imply anything about interpretation or compilation.
4:03:08
pjb
(defun eval (expr) (funcall (compile nil `(lambda () ,expr)))) is another implementation that explicitely invokes the compiler.
4:31:08
aeth
_death: Ime, for technical subjects Wikipedia is good at explaining things, but bad at teaching things. It's okay to read the article on Foo if you already learned about Foo from somewhere else.
4:31:35
PuercoPop
oi, I'm having trouble writing to an unix socket. I've disabled buffering and send finish-output jic. Am I missing something else? https://gist.github.com/PuercoPop/709ac450430cc7097d50d4c02554d304
4:46:00
fiddlerwoaroof
What's the best way to get bindings for a C library? wrapping the types with the groveler than manually writing bindings for the functions?
4:57:07
beach
Or you can write a Common Lisp version of the library that would then benefit the entire Common Lisp community.
5:09:03
fiddlerwoaroof
My goal is to figure out the objective-c runtime well enough that I can fix the beagle backend for clim
5:11:01
beach
whoman: Is that a new discussion topic, or is it somehow related to what fiddlerwoaroof is doing?
7:00:09
White_Flame
I've used the cons cell for the purpose. It tends not to be just the smallest in memory footprint, but in code too
7:02:54
shka
beach: i need to track ownership for shared objects, owner can mutate his object, rest has to copy, i figured that i can stick gensym into box and then add this box to every object. Finalizer of owner will set content of box to nil to indicate that ownership can be taken by any other object.
7:09:46
shka
beach: anyway, it is not that complicated, and all it boils down is to side effect containment. Combined with lazy approach it gives optimized functional containers.
7:11:42
shka
beach: if you are interested in this: http://hypirion.com/musings/understanding-clojure-transients
7:13:27
shka
(that is: it does not prevent code from working, but it is a little bit pointless at certain point)
9:27:33
codesine
What’s a good book or single point of entry for Common Lisp programming especially from a math background
9:29:26
minion
codesine: 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).
9:29:43
beach
codesine: Common Lisp is not considered a particularly function language in that sense.
9:30:07
beach
codesine: So you are going to have a hard time finding a book that does functional programming only in Common Lisp.
9:32:13
beach
"functional programming only" as opposed to "both functional, imperative, and object-oriented programming"
9:33:21
beach
codesine: I should have said: Common Lisp is not considered a particularly functionAL language in that sense.
9:34:37
beach
codesine: Well, since this channel is dedicated to Common Lisp, the opinions here are biased.
9:35:47
beach
codesine: Functional programming is one of the paradigms that Common Lisp supports, but I think it will be hard to find a book that uses Common Lisp and that is all or even mostly about functional programming.
9:38:39
beach
codesine: One important use of functional programming in Common Lisp is in macro expanders, because you typically don't want macro expanders to have side effects. Therefore, a book like On Lisp mostly uses functional programming, but it is a very special use case for that style.
9:41:17
beach
Scheme is also not particularly functional, but maybe Scheme books emphasize that style more often.
9:44:58
Zhivago
I think it's more that recursion looks more functional than iteration, to people who don't realize that iteration is recursion.
9:55:49
Shinmera
It's somewhat convenient for getting a simple app running "directly" on every major OS
10:02:32
_death
it's useful in helping (read "practically forcing") people think about representations that may not be immediately obvious
10:15:38
whoman
C is close to the ... von neu? wait.. asm? x86? way of doing things. close to how the machine works, more so with our current machines than lisp afaik
10:24:45
p_l
VM is just a catch-all for the environment specified to be used by language so you have simple replicated target to write your applications against
10:25:21
whoman
or could i say, the unoptimized disasm of C more closely resembles the machines instructions than for Lisp ?
10:27:43
p_l
nope. unoptimized output of C also tends to not look very modern, though compilers kinda cheat there by not implementing truly unoptimized form in output
10:28:39
whoman
yea ? cuz that part is a bit of an obstacle for me with lisp as i grew up with C, but i really dont see how lisp is any different, if i grew up on that instead
10:30:22
p_l
C gives an illusion of being very low level, but I think it hasn't been true since it left PDP-11
10:31:45
p_l
_death: I know one person who trolled C programmers with standard-compliant C-in-Perl implementation
10:33:06
beach
So in fact, for applications, C is inconvenient, and for "system programming", you have to write nonconforming code to do what you want.
10:33:22
p_l
yeah, also known as "UB" and "compiler is allowed to do anything, including murdering your pet goat, upon encountering that line"
10:35:03
p_l
It's low level in the sense of making you worry about irrelevant (to application you're writing) concerns
10:37:15
p_l
for popular definition of "systems programming", the code is pretty much always full of non-conforming bits, or at least "uses a VM implemented in nonconforming code" as runtime
10:41:09
_death
I think C, Forth, and assembly are prime candidates for an embedded program.. of course, you could use Lisp to generate the code ;)
10:44:32
p_l
_death: assembly doesn't count, since it's essentially an intermediate form of a program generated by something else
10:46:22
p_l
that's not assembly then, just programming the way before assemblers gave us useful intermediate
10:47:39
p_l
I mean that assembler, in its typical form, doesn't count as essentially an intermediate for talking native language of the chip
10:48:28
p_l
hell, PDP-10 bootstrap was handled by handwriting opcodes into registers then swapping them with memory
10:49:20
p_l
_death: and arguably every lisp compiler that generates native code does something like that, though they sometimes happen to not show it directly
10:50:23
_death
p_l: yep.. the other day I pasted https://gist.github.com/death/5ec259ef473b982898a3c5e36b21b1cd
10:56:34
_death
p_l: I also found Kragen Sitaker's urscheme implementation, which generates assembly text, to be very neat.. http://canonical.org/~kragen/sw/urscheme/compiler.scm.html
11:05:34
beach
Shinmera: Yes, it's an independent repository: https://github.com/robert-strandh/Cluster
11:06:54
p_l
btw, does anyone know a single place where I could read about R. Scott McIntyre's CL libs?