lainchan / λ

Lisp General: A Big-City Language

(princ tripcode) -| · 2015-11-22 05:22
This is the Lisp General, ask any and all Lisp questions here. Below is a link to the general's pastebin which contains many links to various books, documentation, websites, and other interesting information. >Check the pastebin first: http://pastebin.com/u/g-lisp-general >Read the FAQ: http://pastebin.com/aDfDm5sZ >To foster discussion: Which dialect do you prefer? Do you use Emacs or a different lisp-based editor? What was your first experience with lisp? What have you made in lisp? What is your favorite Lisp program? What do you like about Lisp? How do you think Lisp is (one of) the superior programming language(s)? How long have you been programming in Lisp? What are your favorite Lisp resources? Please share, preferably links! Is Lisp your main programming language or not? Regardless, what do you primarily use it for? What would you like to see in the Lisp general? What was your favorite aspect of the Lisp machines? Do you think we'll ever get something similar to the LispMs again? What is your preferred method of documenting your code? In the dialects that allow it, do you make many reader macros or not? Do you use more than one dialect? What are they and which do you prefer? What do you consider the criteria for what constitutes a Lisp to be? What is your favorite function in your chosen dialect(s)? Challenge: As painful as it sounds, make something neat with X11.
Anonymous · 2015-11-22 06:33
It takes time to get a hold of it since I work with C at school. I migrate all the programs I do in class to CL to get a hold of it quickly. You learn something new everyday.
Anonymous · 2015-11-22 10:02
Slowly working through SICP in racket. What do you guys think about lambdanative? I want to get into CL eventually but SBCL seems to be the only one with a good license. If I make a CL program and compile it, which includes lots of code from the CL distro, don't I have to open source my code if the CL is under GPL?
Anonymous · 2015-11-22 18:55
>>12255 >What do you guys think about lambdanative? Haven't heard of it until now. Looks amazing honestly, I'll have to give it a shot for Android.
Anonymous · 2015-11-23 23:50
Pleb from last thread again. A Gentle Introduction is meshing with me now. It feels pretty good. This is a program I wrote when working through one of the sets of exercises. Is my form okay? (defun throw-die () (1+ (random 6))) (defun throw-dice () (list (throw-die) (throw-die))) (defun snake-eyes-p (throw) (if (and (= 1 (first throw)) (= 1 (second throw))) t)) (defun boxcarsp (throw) (if (and (= 6 (first throw)) (= 6 (second throw))) t)) (defun instant-win-p (throw) (if (or (= 7 (+ (first throw) (second throw))) (= 11 (+ (first throw) (second throw)))) t)) (defun instant-loss-p (throw) (if (or (boxcarsp throw) (snake-eyes-p throw) (= 3 (+ (first throw) (second throw)))) t)) (defun say-throw (throw) (cond ((boxcarsp throw) 'boxcars!) ((snake-eyes-p throw) 'snake-eyes!) (t (+ (first throw) (second throw))))) (defun craps () (let* ((throw (throw-dice)) (result (say-throw throw))) (cond ((instant-win-p throw) (format t "Throw ~a and ~a - ~a - you win!" (first throw) (second throw) result)) ((instant-loss-p throw) (format t "Throw ~a and ~a - ~a - you lose!" (first throw) (second throw) result)) (t (format t "Throw ~a and ~a - your point is ~a" (first throw) (second throw) result))))) (defun try-for-point (point) (let* ((throw (throw-dice)) (result (say-throw throw))) (cond ((eq point result) (format t "Throw ~a and ~a - ~a - you win!" (first throw) (second throw) result)) ((eq 7 result) (format t "Throw ~a and ~a - ~a - you lose!" (first throw) (second throw) result)) (t (format t "Throw ~a and ~a - ~a - roll again!" (first throw) (second throw) result)))))
Anonymous · 2015-11-23 23:51
>>12315 How I wish my formatting didn't get messed up.
(princ tripcode) -| · 2015-11-24 02:22
>>12315 >Is my form okay? Know that your (if condition t) constructs are unnecessary. The condition will already return t or nil, so you can return that value exactly. You'll also probably want say-throw to return actual strings. Your THROW binding shares a name with a Common Lisp special form, so you should consider finding a new name. The program still works, but Emacs syntax highlighting doesn't do enough introspection to differentiate it. Learning the ins and outs of FORMAT is also very useful. (defun craps (&aux (throw (throw-dice))) (format t "Throw ~{~a~^ and ~} - ~@?" throw (cond ((instant-win-p throw) "~a - you win!") ((instant-loss-p throw) "~a - you lose!") (t "your point is ~a.")) (say-throw throw))) I believe this works equivalently to your version. I also corrected the lack of ending punctuation. You should refactor try-for-point yourself, as an exercise. All in all, I think you did well. Common Lisp can be overwhelming, but learning how to use everything well is very rewarding.
Anonymous · 2015-11-24 22:39
Maybe this is interesting for some of you, unfortunately I don't have many of the requirements, but one of you anons might have. >Lisp Architect - $30/hr, 100% remote position https://careers.stackoverflow.com/jobs/103335/lisp-architect-30-hr-100-remote-position-crossover?a=yEDldN5BBzG
Anonymous · 2015-11-25 00:32
>>12341 looks like it's mostly a C/C++ job.
Anonymous · 2015-11-25 00:48
>>12321 Thanks for the tips. I'll refactor my code when I get home from class tomorrow afternoon. This is the solution to Euler 2 which I figured out late last night. I feel like I did well. I was satisfied, at least. (defun euler-2 (count x y) (when (evenp y) (setf count (+ count y))) (if (> y 4000000) (print count) (euler-2 count y (+ x y))))
Anonymous · 2015-11-25 05:00
just found this http://lisperator.net/slip/ Lisp from your web browser!
Anonymous · 2015-11-25 16:13
>>12345 BiwaScheme is also amazing as well. http://www.biwascheme.org/
Anonymous · 2015-11-25 19:14
>>12321 I ran a Perl script over it to swap all instances of throw to roll. It threw up errors when I removed the t from the (if condition t) functions, so I replaced them with when constructs instead. After I did that the predicates broke (craps never actually used the predicates in its cond block and went straight to the t form). I'm on sbcl so maybe that's not in my implementation. I refactored try-for-point based on your craps function. I'll have to make a reference sheet for format sometime. (defun try-for-point (point &aux (roll (roll-dice))) (format t "Throw ~{~a~^ and ~} - ~@?" roll (cond ((eq point roll) "~a - you win!") ((eq 7 roll) "~a - you lose!") (t "~a - roll again.")) (say-roll roll))) >>12344 I also refactored this to rename count to n because count was already a thing.
Anonymous · 2015-11-25 20:00
>>12364 What's the difference between "(if condition t)" and "condition"?
Anonymous · 2015-11-25 20:09
>>12366 (if condition t f) is identical to condition, but you can have it do something besides return false when condition isn't true.
(princ tripcode) -| · 2015-11-26 03:37
>>12364 > It threw up errors when I removed the t from the (if condition t) functions, so I replaced them with when constructs instead. The lambda list of if is as follows: (if test then &optional else) The then part is not optional. I intended to let you know the entire construction was not necessary, not just the t. (defun snake-eyes-p (throw) (and (= 1 (first throw)) (= 1 (second throw)))) (defun boxcarsp (throw) (and (= 6 (first throw)) (= 6 (second throw)))) (defun instant-win-p (throw &aux (result (+ (first throw) (second throw)))) (or (= 7 result) (= 11 result))) (defun instant-loss-p (throw) (or (boxcarsp throw) (snake-eyes-p throw) (= 3 (+ (first throw) (second throw))))) I don't believe the above has any behavioral differences from yours. If you experience an error that may be relevant to your issues, it would be recommended that you go ahead and post the error so we can see it too. >I'll have to make a reference sheet for format sometime. I use this: https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node200.html >>12344 You can rely on tail-call optimization for your programs, but it is not guaranteed by the standard and not every implementation has it from what I know. >>12366 Condition may return a value that is true, but not t. As an example, 1 and (if 1 t) are both true, but you can see that one returns a number and the other returns the proper true value. This does not matter in the above program, because while AND and OR return the value that short-circuits their execution, = will only return t or nil.
Anonymous · 2015-11-26 07:41
So where do I start with Lisp
Anonymous · 2015-11-26 08:27
>>12374 How much do you know about programming?
Anonymous · 2015-11-26 11:19
>>12374
Anonymous · 2015-11-26 14:08
>>12376 Have a pdf
Anonymous · 2015-11-26 17:02
>>12375 I've taken about 3 semesters worth of introductory computer science at the college level, which in practice means I'm just barely at the level that I understand what functions are and have a broad understanding of oop
Anonymous · 2015-11-26 18:58
What's wrong with my Emacs? When I press ~ it says: <dead-tilde> is undefined. That happens with every dead key. <dead-acute> <dead-diaresis> <dead-grave> all undefined, says it. Major/minor modes have no effect. However, this only happens in the windowed Emacs. Terminal version works normally. This happened out of blue. I have scandinavian layout.
Anonymous · 2015-11-26 19:10
>>12382 Doing C-x 8 ENTER ENTER does it for me in school where the keyboard layout is slightly different from what I have at home. Spanish layout here. By the way, how do you format out the contents of a file?
Anonymous · 2015-11-27 02:23
>>12380 check dis out you can see sicp for a general intro to functional programming, or practical common lisp for a good intro to that language
Anonymous · 2015-11-28 13:14
Man, the lparallel library of Common Lisp is freaking neat. Easy to use pmap function and various other modern parallel constructs.
Anonymous · 2015-11-28 13:27
Does anyone have this book that could share please? https://mitpress.mit.edu/books/scheme-programming-language
Anonymous · 2015-11-28 13:41
>>12408 http://scheme.com/tspl4/
Anonymous · 2015-11-28 16:42
are there any good benchmarks comparing clojure, racket and common lisp implementations?
Anonymous · 2015-11-28 17:51
Why is Chicken so phenomenal? Actually the single best programming environment available. Simple workflow with clear distinction between compiler and interpreter, compiles to C, easy integration with C, tons of library support, easy module/package system.
Anonymous · 2015-11-28 19:01
>>12411 It is pretty great. I like how fast csi starts up and how quickly the code executes. You can just inline C code: #> int bitwise_lshift(int a, int b) { return a << b; } <# (define bitwise-lshift (foreign-lambda int "bitwise_lshift" int int)) (print (bitwise-lshift 1 10)) ; 1024 Pretty neat.
Anonymous · 2015-11-28 19:20
>>12412 What happens with undefined behavior, such as when b is larger than the amount of bits in an int?
Anonymous · 2015-11-28 21:55
>>12413 I think it'd do whatever the C compiler says it'll do. The Chicken compiler only outputs C code anyway, so it shouldn't have an effect on how undefined behavior is handled (because it'd still exist in the code). #> int bitwise_lshift(int a, int b) { return a << b; } <# (define bitwise-lshift (foreign-lambda int "bitwise_lshift" int int)) (let loop ((n 1)) (let ((next (bitwise-lshift n 8))) (print next) (unless (> n next) (loop next)))) ; output: ; 256 ; 65536 ; 16777216 ; 0 Trying to pass something like 0.5 to either argument of bitwise-lshift just results in an error (from foreign-lambda, I'm guessing).
Anonymous · 2015-12-01 00:29
Don't forget about the challenge.
Anonymous · 2015-12-01 03:15
>>12428 What does "with X11" even mean? Just a graphical program?
Anonymous · 2015-12-01 03:40
>>12430 >What does "with X11" even mean? Just a graphical program? Basically, unless you're on Windows, although you could get creative and do something not graphical that still uses a facility of X11, like reading mouse movements.
Anonymous · 2015-12-01 09:54
>>12383 Yeah that's a clumsy workaround, as is this line in .emacs I found from archwiki: (require 'iso-transl) It still doesn't work normally with that. Normally in any other application when pressing any dead key twice it would produce that accent character on its own. With that line it "works" but requires some other character to be pressed after that. I even have custom keybind to remap doubletap of one dead key to tilde like (local-set-key (kbd "¨") (kbd "~")) ...and no, my .emacs is not at fault here, tested with emacs -Q Emacs has worked before, meaning that it behaved like any other application! I've been using this for about two years now as main editor, on same distro and it has always worked. Something weird has happened. I even compiled fresh Emacs 24.5 off the sources and it has the same problem, so it's not some distro packaging fukup. I also tried asking around in #emacs@freenode but they weren't very helpful to put it lightly. *sigh* I'm on verge of giving up on Emacs and lisping with it for lack of tools. I simply don't have time or interest to spend my days troubleshooting some weird problem when I have n+2 other things to do.
Anonymous · 2015-12-01 10:54
>>12440 I'm only vaguely aware of what's happening, but perhaps you should look into binding xdotool to these "dead keys".
Anonymous · 2015-12-03 20:30
>>12443 I zeroed the problem into something that Emacs fails when it receives keystrokes from X11 or whatever. Because Emacs works as excepted in Windows 10. That is, doubletapping dead keys works the same in all Windows applications, including Emacs. Well, it's been a while since I last used Windows, might as well stay here indefinitely.
Anonymous · 2015-12-04 00:27
Who's tired of forgetting command line parameters for badly named system utilities? Lets make a modern lisp machine: >>12467