[ cyb / tech / λ / layer ] [ zzz / drg / lit / diy / art ] [ w / rpg / r ] [ q ] [ / ] [ popular / ???? / rules / radio / $$ / news ] [ volafile / uboa / sushi / LainTV / lewd ]

λ - programming

/lam/bda /lam/bda duck
Name
Email
Subject
Comment
File
Password (For file deletion.)

BUY LAINCHAN STICKERS HERE

STREAM » LainTV « STREAM

[Return][Go to bottom]

File: 1448169759527.jpg (1.34 MB, 2001x773, Space-cadet.jpg) ImgOps Exif iqdb

 No.12245

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.
>>

 No.12247

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.

>>

 No.12255

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?

>>

 No.12272

>>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.

>>

 No.12315

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)))))

>>

 No.12316

>>12315
How I wish my formatting didn't get messed up.

>>

 No.12321

>>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.

>>

 No.12341

File: 1448404793381.gif (476.13 KB, 200x175, 1416858631575.gif) ImgOps iqdb

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

>>

 No.12343

>>12341
looks like it's mostly a C/C++ job.

>>

 No.12344

>>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))))

>>

 No.12345

just found this http://lisperator.net/slip/
Lisp from your web browser!

>>

 No.12358

>>12345

BiwaScheme is also amazing as well.

http://www.biwascheme.org/

>>

 No.12364

>>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.

>>

 No.12366

>>12364
What's the difference between "(if condition t)" and "condition"?

>>

 No.12367

>>12366
(if condition t f) is identical to condition, but you can have it do something besides return false when condition isn't true.

>>

 No.12372

>>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.

>>

 No.12374

So where do I start with Lisp

>>

 No.12375

>>12374

How much do you know about programming?

>>

 No.12376

File: 1448536742811.jpg (32.54 KB, 318x400, Common-LISP-Touretzky.jpg) ImgOps Exif iqdb


>>

 No.12377

File: 1448546899115.pdf (1.08 MB, 1448238309710-tech.pdf)

>>12376
Have a pdf

>>

 No.12380

>>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

>>

 No.12382

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.

>>

 No.12383

>>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?

>>

 No.12389

File: 1448591008563.pdf (2.25 MB, The Little Schemer 4th Ed.pdf)

>>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

>>

 No.12407

Man, the lparallel library of Common Lisp is freaking neat.

Easy to use pmap function and various other modern parallel constructs.

>>

 No.12408

Does anyone have this book that could share please?
https://mitpress.mit.edu/books/scheme-programming-language

>>

 No.12409


>>

 No.12410

are there any good benchmarks comparing clojure, racket and common lisp implementations?

>>

 No.12411

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.

>>

 No.12412

>>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.

>>

 No.12413

>>12412
What happens with undefined behavior, such as when b is larger than the amount of bits in an int?

>>

 No.12416

>>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).

>>

 No.12428

Don't forget about the challenge.

>>

 No.12430

>>12428
What does "with X11" even mean? Just a graphical program?

>>

 No.12431

>>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.

>>

 No.12440

>>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.

>>

 No.12443

>>12440
I'm only vaguely aware of what's happening, but perhaps you should look into binding xdotool to these "dead keys".

>>

 No.12466

>>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.

>>

 No.12468

File: 1449188837538.gif (2.69 MB, 309x301, jelly.gif) ImgOps iqdb


Who's tired of forgetting command line parameters for badly named system utilities? Lets make a modern lisp machine:


>>12467



Delete Post [ ]
[ cyb / tech / λ / layer ] [ zzz / drg / lit / diy / art ] [ w / rpg / r ] [ q ] [ / ] [ popular / ???? / rules / radio / $$ / news ] [ volafile / uboa / sushi / LainTV / lewd ]