freenode/#lisp - IRC Chatlog
Search
7:44:18
reepca
Is there a way to conditionally indent within a line with the pretty-printer? I'm pretty-printing some unstructured code that alternates between instructions and labels. I need the labels to be on their own line at a certain lesser indentation, and the code to be on its own line (but with multiple instructions on the same line as much as possible). However, labels can come one after the other, so setting the indentation prior to
7:44:19
reepca
finishing one label doesn't work, since it's necessary to know whether the next line will have another label or instructions.
7:45:16
another-user
i tried to write bf2 CL benchmark for https://github.com/kostya/benchmarks but it's slower than Racket, how can i speed this up? https://dpaste.org/rsEY
7:47:09
another-user
they used unsafe-vector-* but otherwise the program looks sameish: https://github.com/kostya/benchmarks/blob/master/brainfuck2/bf.rkt
7:48:19
reepca
the way I have it currently it all looks okay until labels are adjacent to each other, at which point there are blank lines between them because I use ~& and an indented line isn't "fresh". But if I finish a label without the indentation, how do I indent that line? Indentation only occurs by the pretty-printer after newlines apparently.
7:49:57
White_Flame
oh, and you're using adjustable & fill-pointer, that makes all of your arefs expensive
7:50:25
no-defun-allowed
You could change the representation to use structures, which might be faster than accessing a list.
7:56:03
smokeink
reepca: you can check out the "out" macro in ytools, it has some functionality related to indenting if I remember well
7:57:12
no-defun-allowed
Using a fixed tape of 4,096 fixnums drops the execution time to about 6.5 seconds from 15.
7:57:15
p_l
BTW, regarding CL on microcontrollers, remember that writing compilers is a classic Lisp technique ;)
7:58:00
no-defun-allowed
You could probably drop the "interpreting" overhead entirely by converting the Brainfuck program to a Lisp program and passing it to COMPILE.
7:59:19
aeth
no-defun-allowed: yes, that's what I do with my Brainfuck... I just compile it down to a lisp program that's like (incf (aref a *position*) 1) etc.
7:59:36
no-defun-allowed
In a chip8 interpreter I wrote long ago, naive compilation gave me at least a 10x speedup over interpretation.
7:59:43
aeth
no-defun-allowed: idk how far I go, there are basically a ton of optimizations you can do to produce better output. e.g. instead of incf'ing one at a time, you can see how many +++s there are and incf by that amount
8:02:33
another-user
White_Flame, no-defun-allowed: thank you for tips! algo must be similar between implementations - other impls use infinite tape
8:03:08
no-defun-allowed
ACTION will test compiling next. She really likes making compilers for some reason.
8:03:30
aeth
another-user: I think generally, the tape that's used in Brainfuck is wrapping tape rather than truly infinite. So some large circular buffer as an array.
8:04:47
White_Flame
if you manually manage the tape growth, instead of using vector-push-extend, then your arefs will be simple inline accessors
8:06:09
aeth
Yes, but if you have a fixed length tape and you compile the Brainfuck as a function, then there are no length checks at all because the tape doesn't grow. Even if it can change from program to program, the AREF specific to that program will know the length (assuming it's all in one function or there are declarations)
8:14:32
another-user
no-defun-allowed: i tried https://dpaste.org/tTEB but it didn't win much time(~1s)
8:15:27
no-defun-allowed
I'll show you my code after I write that kind of reader. The other two big wins are inlining everything and using a simple-array to get AREF really fast.
8:20:14
no-defun-allowed
You can add the unsafe declaration to the generated code in compile-bf-program, which takes it to 1.35 seconds, but admittedly I don't think it's usually worth doing so in real programs.
8:26:07
no-defun-allowed
Is there such a thing as a regular expression that operates on lists, and is there an implementation of that?
8:28:38
no-defun-allowed
aeth: I would want to merge all the tape-inc instructions together, preferably by writing a rule like (:many (tape-inc ?x)) => `(tape-inc ,(reduce #'+ ?x))
8:29:03
no-defun-allowed
That might be too much wishful thinking, and I could probably write it somehow without it.
8:30:03
aeth
no-defun-allowed: well, you could also do actual regular expressions and instead of parsing #\+ as (tape-inc whatever) you'd parse "++++" as (tape-inc whatever 4)
8:31:47
beach
no-defun-allowed: Check out the works by Jim Newton. That's exactly what they are doing.
8:33:59
no-defun-allowed
aeth: I modified the reader to merge multiple + characters together into one operation, and that takes the execution time to 0.8 seconds.
8:35:07
smokeink
in sbcl loading a .lisp file that has (declaim (optimize (safety 3) (debug 3) (speed 0) (space 0))) , should actually change the policy? when I do (describe-compiler-policy), it's not changed
8:35:45
smokeink
if I run sbcl with (declaim (optimize (safety 3) (debug 3) (speed 0) (space 0))) in sbclrc , it works, the policy is changed
8:36:49
no-defun-allowed
So, another-user, using a compiler such as that one creates code that runs 30x faster than the C++ interpreter in that repository.
8:37:13
jackdaniel
beach: to be precise, declaim is guaranteed to take effect for a file at compile time in which it is a top-level form, it is not specified whether effect lingers after the file is compiled
8:38:17
aeth
no-defun-allowed: There are some other idioms you can detect other than just a bunch of +s and -s in a row. The more you can detect, the better it will run. I mean, for someone who tries to "structure" Brainfuck rather than code golf.
8:39:31
White_Flame
declaiming non-optimization stuff liek types does stick past the file context, iirc
8:40:30
jackdaniel
White_Flame: it *may* stick, it doesn't necessarily stick (you can't portably rely on that) - use proclaim in eval-when to assure that they stick
8:41:36
beach
White_Flame: The standard allows for the startup environment and the compilation environment to be separate.
8:44:05
no-defun-allowed
Folding the other characters like that yields only a .02 second improvement, but hopefully that is more than what was expected for the benchmark.
8:45:08
no-defun-allowed
The readme does say "It interepter all bf instructions, one by one, without any squash or other hacks", but it's not *my* fault those other languages can't let you use the compiler at runtime.
8:46:35
beach
smokeink: It seems that in SBCL, this particular aspect is separate in the run-time environment and the compilation environment.
8:46:50
smokeink
beach: if I do sbcl --no-userinit --no-sysinit --load ~/.sbclrc (.sbclrc contains that eval-when) it has no effect. but if i just do sbcl , it has effect
8:48:07
smokeink
I need it to have effect when I use --load , because I do some stuff before loading it
9:08:59
smokeink
SBCL 2.0.0.73-7d05b4c https://paste.ofcode.org/uc2PrgJASAaWgkS5FsUBGA during macroexpansion of (SB-PCL::%DEFMETHOD-EXPANDER INSPECT-OBJECT-USING-STATE ...)) failed AVER: (= SB-C::COMPONENT-TLF-NUM SB-C::TLF-NUM) This is probably a bug in SBCL itself.
9:14:34
jackdaniel
smokeink: did you try to load the dependencies and compile the file after that without the quickload forms?
9:15:18
jackdaniel
I can imagine that first macros are expanded with old definitions, then quickload is executed and some internal references become bonkers
9:25:02
smokeink
jackdaniel: quickloading first, works, but the generic methods don't get called, the mean and standard deviation doesn't show up in clouseau
9:25:52
smokeink
I just wanna play a little with clouseau, what's a sbcl version that works well with it ?
9:26:37
smokeink
a version that can run the above snippet and shows the standard deviation and mean, would be enough for me today
9:45:14
scymtym
smokeink: i didn't change those methods recently and i also load Clouseau from McCLIM master daily. i think this is about SBCL, not Clouseau
9:45:40
ralt
(ql:system-apropos "...") will list the relevant packages, but no way that I can see to check the descriptions.
9:46:21
imherentlybad
is there a away to add a directory where quicklisp scans for projects, much like quicklisp/local-projects/ ?
9:46:29
smokeink
https://stackoverflow.com/questions/38684906/how-to-get-package-documentation-in-quicklisp
10:35:47
flip214
what's the short form for (APPLY #'fn1 (M-V-L (fn2)))? Isn't there some MULTIPLE-VALUE-
12:29:23
pjb
minion: memo for asarch: genera and instructions can be found at: https://cliki.net/VLM_on_Linux
13:18:16
lieven
minion: memo for asarch: for recent X versions, you need to patch genera. See https://archives.loomcom.com/genera/genera-install.html#org783aa06
13:20:49
chimneys
I have to know how lisp is more powerful, say if I write a program to open 1000 emails in python it works, so programs can do things that cannot be done manually , similarly give an example in which lisp can generate programs 1000's of them which simply can't be done using python manual programming.
13:22:44
lieven
python is turing complete and so can trivially do anything Common Lisp can, if necessary by implementing Common Lisp in python. See Greenspun's rule and the blub paradox.
13:28:16
beach
chimneys: As lieven says, Common Lisp is no more powerful than any other Turing-complete language, so there is nothing that can be done in Common Lisp that can't also be done in any other Turing complete language. It might be more convenient to do certain things in Common Lisp than in (say) Python, but those things can still be done in other languages.
13:31:15
beach
chimneys: If you think that the language doesn't influence your productivity, you should probably not waste your time learning Common Lisp.
13:31:17
chimneys
for example you could say I can make million email-ids using mouse and keyboard, yes but it will take forever. so is there any metaprogram that generates programs that can't be generated but manually one by one
13:32:11
lieven
ralt: python function annotations can run arbitrary code at function definition time so close enough I guess
13:33:04
beach
chimneys: Shinmera is (rightly so) concerned about other #lisp participants wasting valuable time from their respective projects.
13:38:15
jayspeer
heh, and you guys wonder why so few people use lisp :D get that stick out of your a**
13:40:54
nickerpro
i came to lisp because i thought i could do cool thing in it, they say ti's turing complete like python so nothing special
13:41:00
beach
I think I have a fairly good idea as to why relatively few people use Common Lisp. And it is nothing that could be fixed by participating in this kind of discussion.
13:41:13
flip214
chimneys: IMO one of the major advantages is that CL allows for a much bigger bandwidth of abstractions. You can easily build very high-level abstractions (classes, and macros for eg. control flow), but also influence the generated machine code.
13:42:40
Shinmera
jayspeer: We get this same shit every week. It doesn't help, and it's mind numbingly boring noise.
13:42:41
beach
No, "special". You said "so nothing special". And I am saying there is something special, but it is not Turning completeness.
13:43:29
flip214
chimneys: as an example, macros in lisp allow you to build an abstraction for defining classes and methods on them
13:43:45
jayspeer
Shinmera: maybe bot can automatically message user with relevant links? It would both take it off us and provide useful information
13:45:42
beach
jayspeer: I think an answer from a real person is more valuable, and why try very hard to give good answers to good questions. Besides, the kind of people who have bizarre questions probably wouldn't read the document that the link refers to.
13:48:07
pjb
Responses from a real person are good only if the telepathic link can be established, so that the response given may lead the asker to the real answer to the actual question he had.
13:53:03
beach
Shinmera: Interesting observation that there is more stuff like this during the weekend.
13:57:07
phoe
when it comes to the languages themselves, I'd say so, yes - the interactivity is really fun when you get to play with the language
13:57:25
jackdaniel
good programmers will write good code in both, although cl could be much of an aid to do so
13:57:54
beach
chimneys: There are almost no scientific studies that compare the productivity of programming languages, and the ones I know of do not feature Python. So it boils down to personal preference.
13:57:55
phoe
I love myself an interactive debugger&inspector combo that's always present and allows you to inspect the stack, check on the values bound to the variables there
13:59:05
phoe
plus the REPL that's a part of developing in the language - you never really go "$ python my-script.py" like I did when writing Python, you run Lisp once and have it running in the background all the time while you compile a function after a function into the Lisp image, likely playing with it in the REPL after each compilation to check if it does what you hope it does
14:00:07
beach
It's too bad though. Some national or union-wide agency should invest in such a study.
14:00:32
phoe
it's less of tweaking a Massive File Full Of Code™ and more of playing with individual forms that you then send into Lisp - more like a conversation with the language that runs in the background than starting from a clean slate every single time when you run a program written in Python or C++ or another non-interactive language from scratch
14:06:18
phoe
a lot of that also boils to personal proficiency and preference, so is highly variable
14:06:44
phoe
but after trying both python and lisp I like the lisp environment more due to the interactivity and the amount of introspection that's available in there
14:08:42
phoe
jayspeer: at the same time I understand some people who are tired of this sort of discussion, mostly due to the "fame" that Lisp has on the Internet
14:09:15
phoe
"OMG it's t3h language that makes the impossible possible and the possible trivial, it's the MAGIC SECRET SAUCE™©® known only to some W I Z A R D S"
14:09:26
pjb
Once upon a time, I made a #clnoobs channel so that newbies could ask their newbie questions there without bothering the serious and advanced #lisp programmers…
14:11:08
phoe
I got that sort of impression from e.g. reading multiple Graham writings, and I directly blame him for that sort of popularity. He didn't write it like that literally, of course, but he certainly attributes too much to to Lisp itself.
14:12:31
phoe
Using a particular language won't instantly cause you to become a better programmer. Sure, working with Lisp for some time will have an effect on your overall code quality, but there's no "enlightenment" that is mentioned somewhere, there's no magic in here that will suddenly pour down into your fingers and all over your keyboard.
14:13:44
pjb
There's enlightenment! It can be achieved reading sicp (or wathching the sicp lectures).
14:16:19
phoe
jackdaniel: I'd imply it's positive, since e.g. in Lisp it's easy to try and express the same idea in multiple ways due to the fact Lisp is multi-paradigm. At least in my case, I got a few "ah-ha!" moments when I realized that the same problem can be approached from a different way and the language doesn't stand in my way when I want to go functional, or object-oriented, or declarative, or even linear or via a
14:17:59
phoe
where I can consult other people and actually figure out if the idea I'm trying at the moment is worthwhile or trashy.
14:18:38
phoe
anyway, about the magic - Lisp has multiple advantages over the years, so many that other languages have copied many features from it that are now considered "industry standard". I think that's one thing to keep in mind when glancing at the language
14:19:20
phoe
s/enjoy the #lisp part of Lisp/notice that consulting with the folk of #lisp has a direct positive effect on the quality of my code/
14:21:46
phoe
but then, code review is important in *any* programming language you're writing - so nothing that is really particular about Lisp in this case
14:22:44
phoe
as well as provides some context about the "aw shit, here we go again" reactions that happen on this channel - and why I blame Graham for that sort of stuff (;
14:26:04
Nilby
I think it's reasonable to say those that ask questions without basic understanding: "Don't use Lisp. Thank you. Please go away." For me, and likely those of you who are rebellious enough to write a lot of Lisp code, such an answer would only serve to increase my determination to learn it. But people who ask about how to cons, cdr, etc. should be treated with great kindness.
14:28:10
pjb
dlowe: perhaps it was discussed here, and I said somebody should make a #clnoobs channel, and somebody did?
14:48:35
phoe
luis: (ql:system-apropos "base64") followed by a series of (length (ql:who-depends-on ...))
14:49:02
phoe
this doesn't include transitive dependencies but in this case I guess the inaccuracy is bearable
14:53:35
luis
seems like s-base64 can't encode character streams. It might be a reason to use cl-base64 instead.
15:00:11
luis
jdz: cl-base64 has a stream-to-base64-{stream,string} symbols but no defined functions. Am I missing something?
15:01:37
ralt
was trying to think of a way to debug a production image without bothering production environment
15:04:26
jdz
Oh, right, I remember: I only need to decode stuff, and I've added stream versions for that.
15:06:02
luis
jdz: you might want to publish your fork on Quicklisp, maybe? You can call it jdz-base64 or amR6LWJhc2U2NA== or something :)
15:06:29
pjb
ralt: alternatively, you can use clisp who knows how to save images without killing itself.
15:08:41
pjb
I don't remember. It can re-open the open files, if they still exist when you reboot the image.
16:17:13
jmercouris
we are using trivia in our project, and I really don't like the 'trivial-x' libraries or the "_" as OTHERWISE
16:30:49
jmercouris
galdor: A variable-pattern matches any value and binds the value to the variable. "_" and "otherwise" are special variable-patterns (a.k.a wildcard-pattern) which match any value but don't bind.
16:37:51
galdor
I personnally do not like OTHERWISE in general, looks too much like "we did not have a better solution so let's introduce a special symbol"
16:45:40
remexre
is there a standard macro for "set this value in this place if the place's current value is nil"?
16:55:20
Bike
(defmacro supercalifragilisticexpialidocious (place value) `(unless ,place (setf ,place ,value)))
17:26:00
phoe
eeeeeta: I could probably write a macro to programmatically generate 80% of German speech
17:36:20
asdf_asdf_asdf
'(1 2 3) collecting i => (1 2 3) '(1 2 3) by #'skip-arg-1 collecting i => (1 3).
17:37:18
beach
asdf_asdf_asdf: (loop for element in '(1 2 3) for i from 0 unless (= i 1) collect element)
17:38:22
HiRE
It seems to repeat whatever is after the collecting part in the list you're looping over
17:38:49
beach
It takes the argument and sticks it in a list, which is then returned at the end of the loop.
17:39:13
Xach
asdf_asdf_asdf: (loop for i in '(1 2 3 4 5) by (first-then #'cddr #'cdr) collect i) is one option
17:42:53
Xach
one possibility: (defun first-then (&rest funs) (let ((fun (pop funs))) (lambda (obj) (prog1 (funcall fun obj) (setf fun (or (pop funs) fun))))))
17:44:43
beach
How does that help if the argument to BY is evaluated only at the beginning of the loop?
17:45:50
beach
(first-then #'cddr #'cdr) is evaluated only once, at the beginning of the loop, so how can this implementation of it solve the problem that asdf_asdf_asdf has?
17:45:55
Bike
the returned closure has the effect of cddr the first time and cdr subsequent times. there is only one closure but it maintains its own state, so the loop doesn't need to evaluate the function more than once. makes sense to me.
17:49:27
eeeeeta
Xach: and, thankfully, Lisp is a language where you can get away with not knowing that sort of thing? :p
17:50:52
eeeeeta
ACTION suggests Xach turn in the source code of quicklisp instead and leave it at that :D
17:51:24
Xach
oh god, that would earn me a very poor grade - the fact that people find it useful counts for nothing
18:01:16
HiRE
ah yes, monads are quite simple. They are just monoids in the category of endofunctors
18:04:49
asdf_asdf_asdf
Thank You Beach, Xach. I want Xach's example. How pop n item from list using keyword "by"?
18:09:08
ck_
ACTION puts "by implementing the desired semantics" into the book of phrases for a rainy day
18:09:41
asdf_asdf_asdf
(loop for i in '(1 2 3 4 5) by (nth 3 :default-list) collect i) => '(1 2 3 5)
18:16:21
phoe
https://stackoverflow.com/questions/4093845/is-there-a-common-lisp-macro-for-popping-the-nth-element-from-a-list
18:21:57
asdf_asdf_asdf
phoe, thanks. I want example above, but with (nth x y), not always second item.
18:24:12
phoe
asdf_asdf_asdf: that implementation of CDNTH and (SETF CDNTH) in the above answer seems correct though
19:02:38
pjb
beach: I can't even find where in clhs the semantics of for in by and for on by is defined. It's present in 3 loop clauses; by is described for 6.1.2.1.1 The for-as-arithmetic subclause, but doesn't say if the form is evaluated once or each time (but the example are as if evaluated once).
19:12:30
Xach
asdf_asdf_asdf: you could use (first-then #'cdr #'cdr #'cdr #'cddr #'cddr)! but that is ugly.
19:31:02
no-defun-allowed
cl-base64 has a helper function to convert a base64 string into a string, but I believe it's broken for non-ASCII characters.
19:32:45
no-defun-allowed
So, to use either library with text, you will also need to use the Babel library to convert an array of octets to a string and back.