lainchan / λ

Lisp General: Previously Garbage Collected

(princ tripcode) -| · 2017-04-12 02:45
This is the Lisp General, ask any and all Lisp questions here. Below is a link to the general's texts which contain many links to various books, documentation, websites, and other interesting information. >Check the texts first: https://lainchan.org/~lisp/ >Read the FAQ: https://lainchan.org/~lisp/faq.txt >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: Write some utility functions or other enhancements that would be useful in other programs; provide an archive of the last Lisp General, if you have one.
(princ tripcode) -| · 2017-04-12 02:48
Note that my directories aren't currently reinstated, but this is no issue, as backups are available once ready. Also note that my tripcode has changed; that's a shame, as the other had ``src/'' in it and I liked that. Anyways, this will be moved to /λ/ soon. Let's discuss our latest developments and continue from where we left off, for now.
Nobody special · 2017-04-12 03:36
What is lisp used for nowadays? is it fast?
Marly Krushkhova · 2017-04-12 04:03
>>5 While not a language property, Common Lisp and Scheme can be very fast. They both have implementations that compile directly to machine code. Did you know that C's printf() interprets the control string every time, unless it's simple enough for the compiler to optimize it away? Common Lisp has a FORMAT function, which is not only more powerful, but a FORMATTER function, which returns a function that outputs the string; this means that a format string can be optimized directly to machine code on an implementation such as SBCL (Steel Bank Common Lisp). Similarly, the Chez Scheme implementation also compiles to machine code. I have a saying: ``Metaprogramming is required for efficiency.'' I'll provide a very real example I'm fond of. The Perl regular expression subsystem is written in C and compiles regular expressions to a bytecode to be executed at runtime. Meanwhile, the CL-PPCRE (Common Lisp Portable Perl-Compatible Regular Expressions) library compiles regular expressions to Lisp functions which are then used. Because of this, regular expressions can be compiled to machine code under this library, which isn't the case with Perl, even now, as far as I'm aware of. Because of this, as of the last time I've checked, CL-PPCRE is faster than Perl. Being able to manipulate programs outside of their running time is very important for optimization, as the programmer will always know more intimate details than the compiler for the foreseeable future.
Ivan Horvat · 2017-04-12 18:07
Are there any archives of the previous threads? Maybe we should have a discord just in case everything explodes again.
(princ tripcode) -| · 2017-04-12 18:57
>>7 >Are there any archives of the previous threads? I'd it on my machine, but it lost power and so the state. This is in the challenge for this thread. >Maybe we should have a discord just in case everything explodes again. Discord is proprietary software, so no. Here's a solution: I've a website here: http://verisimilitudes.net Currently, there's only an article concerning an esoteric language I created and I've not yet updated it or the supporting files, so try not to judge it too harshly. I've also not bothered with Let's Encrypt yet. In short, it needs a great deal of work, but I've already planned several articles. Anyways, if there's truly nothing left, I'll direct from there, alright?
Cutter · 2017-04-12 19:59
>>8 >Discord is proprietary software um try again sweetie ;) jk
Tequila · 2017-04-12 20:39
Daily reminder that LISP is the best.
Roy Batty · 2017-04-12 21:03
>>5 I've heard its very good for machine learning and genetic algorithms, but I'm not really a programmer so I don't know why.
Dujour · 2017-04-12 21:18
>>11 We could use a lainchan matrix channel (http://riot.im) as a discord alternative, but that should have its own thread. why no love for racket guys. Racket is a framework for languages with its own language of the same name but also has support for scheme and other languages. The amount of libraries and packages is amazing and its a real breeze to work with and make nice software fast. I used many languages in the past, but with racket i feel finally like i have one that suits me. give it a try at http://racket-lang.org
fsociety · 2017-04-12 21:26
I recently saw an article about using Lisp for web development, specifically on the backend for web applications. Is this feasible in comparison to using PHP, as an example, for this purpose?
Unspecified · 2017-04-12 21:56
I am trying to learn Clojure. What is your favorite Clojure book? I have started reading "Clojure for the brave and true," but I think it moves to slow and takes to much time with jokes. I saw some good reviews of "The joy of Clojure," but no exercises, so I dont see the point.
The Plague · 2017-04-12 22:27
>>23 I'm doing the exact same thing except i started with the "Joy of closure", blocked when examples started to get slightly more complex (probably due to my soykaf attention span) and ended up following "clojure for the brave and true" I'm totally new to the functionnal paradigm and never really used emacs so i especially appreciated the part where it spoonfeeds you how to set your development environment up.
Neo · 2017-04-12 23:03
https://itch.io/jam/lisp-game-jam-2017-easy-mode A lisp game jam is about to start soon, anyone joining?
Ender · 2017-04-12 23:08
>>27 does lisp have quality game engines?
(princ tripcode) -| · 2017-04-12 23:48
>>17 >We could use a lainchan matrix channel (http://riot.im) as a discord alternative, but that should have its own thread. If it really came down to it, I'd install an IRC serving program on my server. >why no love for racket guys. There was a dedicated Racket thread in old /λ/ that fragmented discussion and later largely stagnated. >Racket is a framework for languages with its own language of the same name but also has support for scheme and other languages. >The amount of libraries and packages is amazing and its a real breeze to work with and make nice software fast. Dr. Racket is nice. Do you believe people favor Common Lisp in many ways in part because it was designed as the unifying Lisp for large projects? Do you feel that Racket still hasn't shaken the pedagogical image of Scheme? One issue I find bothersome is the lack of Racket implementations, but the switch to Chez Scheme should help amend this. The eventual goal seems to be to implement Racket almost entirely in itself for ease of porting. >>19 I believe so. Lisp is rather easy to use and there are libraries to convert S-expressions to HTML and whatnot. >>27 I see this question raised every year and I think I actually might this time. The reminder is appreciated.
Hacker · 2017-04-12 23:57
We should start a server on freenode again. I know we have a lainchan irc, but most people are in freenode channels anyway. The move to lainchan irc seemed to be one of those 2deep4u things, and split the community even more.
Backus · 2017-04-13 00:17
>>29 The cl bindings for SDL2 and GL are really good, managed to make simple snake and 2048 clones really fast with them. >>27 I wanna. We should have a thread for stuff like that
Debbie Charteris · 2017-04-13 03:48
I've started learning common lisp, it's been enjoyable. Since I haven't passed the point of no return, should I learn haskell, scheme, asm86, or lisp first? mostly interested in malware development, for fun. i know assembly and c are most common for this, but haven't seen anything saying which I shouldn't use lisp for it.
Acid Burn · 2017-04-13 04:09
>>37 If you're looking for malware, assembly is your best bet. But you already said it so why am I echoing? Perhaps FORTH would be a good alternative. Haskell certainly wouldn't, it requires a soykafload of runtime. Common Lisp also requires a huge runtime. Perhaps Scheme, particularly the TinyScheme implementation, though you'll have to put your C skills to use as well. I think some famous adware was made with TinyScheme. In general, there is no reason you couldn't do malware with any language, the topic is really broad. I mentioned runtime because I've mostly done malware in the form of viruses, which need to be as small as possible. However, I don't see why you couldn't make, say, a botnet with any of those languages.
Molly Millions · 2017-04-13 04:12
>>37 >Since I haven't passed the point of no return, should I learn haskell, scheme, asm86, or lisp first? Well, this is the Lisp thread, so I'm going to say continue on with Lisp. It won't hurt you. >mostly interested in malware development, for fun. i know assembly and c are most common for this, but haven't seen anything saying which I shouldn't use lisp for it. My first instinct is to say that Lisp isn't suited to malware, but read this: http://philosecurity.org/2009/01/12/interview-with-an-adware-author For certain types of malware, you're going to be best off with learning machine codes. I'm about to make a thread for this very topic, so perhaps you can ask any questions you have about this type of malware there. Just check the catalog in a bit.
stack · 2017-04-13 04:47
>>39 Scheme/TinyScheme could be interesting, appreciate the suggestion. I'll check out FORTH too. >>40 Of course, I'd like to learn lisp either way. >machine codes Where I assume assembly excels especially. Part of the reason I've taken an interest in malware writing in less common languages is crypting/polymorphic viruses. Obviously assembly is low level and thus more difficult to decompile, but it also utilizes more common system calls which may be caught more often by AV. I haven't seen viruses in more esoteric languages decompiled, but I don't know if this is because people already know it's a bad idea, if it's actually difficult, or it just hasn't been attempted. The specific project I have in mind is a botnet, specifically a re-implementation of an HTTPS botnet according to the Vault7 HIVE data, where runtime might be less of an issue. In fact, since it probably won't ever be deployed, might not be an issue at all. Writing it in an unsuitable language might mean I could release the source without major consequence (e.g. skids deploying it) which could be nice.
Hacker · 2017-04-13 06:02
No one had put them up yet so here are the .txt files from ~lisp that I had saved. Pretty useful stuff. https://pastebin.com/GZQPR3hF https://pastebin.com/V0bJPYwB https://pastebin.com/zNYDTzEN https://pastebin.com/CE3mVV23 https://pastebin.com/vMpDAEpT https://pastebin.com/BfHhShK7 https://pastebin.com/wHTm0PWb https://pastebin.com/EY5TR9dP https://pastebin.com/9Svgf0m1 https://pastebin.com/DKZxmZEU https://pastebin.com/GbWhqL58 https://pastebin.com/nF8s0LLK
Arisu Mizuki · 2017-04-13 08:27
>>17 > There was a dedicated Racket thread in old /λ/ that fragmented discussion and later largely stagnated. It didn't fragment discussion, it was a thread about Racket. Nothing wrong with that. >>17 Racket is really nice, the only thing I don't like is Dr.Racket, or the fact that Racket assumes the use of Dr.Racket for most of the functionality. It's the "only" thing that keeps me from fully diving in. >>37 > Since I haven't passed the point of no return, should I learn haskell, scheme, asm86, or lisp first? That is, as always, a hard question to answer. Lisp and Scheme are awesome, which specific ones are you interested in? I would encourage you to at least take a look at Haskell, it is a pretty fascinating language.
Cereal Killer · 2017-04-13 09:27
>>7 >>8 >>17 >>30 I can add an IRC channel on my server if you want. The address is barton.lain.tokyo with SSL on port 6697, the main channel is #general and you have to wait for verbose mode.
Moore · 2017-04-13 11:04
What's the seasoned lisper's opinion of Shen? Is it worth learning? It looked pretty interesting to me because it seems to have very powerful typing facilities, but I'm not sure if I should invest my time into learning it.
Colmerauer · 2017-04-13 16:14
>>90 I'll wait for 5-6 people more before creating the #lisp room.
Pulse · 2017-04-13 16:20
Is there any documentation on the internet for the Symbolics Ivory processor that was used in last Lisp machines? I checked Bitsavers, googled around, but found nothing substantial. Asking before I start reverse-engineering it myself.
bit · 2017-04-13 17:48
>>25 http://iloveponies.github.io/120-hour-epic-sax-marathon/I-am-a-horse-in-the-land-of-booleans.html I started reading that one. It looks alright so far, easy tone, good examples and "graded" exercises.
Hiro Protagonist · 2017-04-13 18:34
>>30 >Do you feel that Racket still hasn't shaken the pedagogical image of Scheme? Racket is still mainly used as an introductory language, so even though it has a LOT of tools in its standard library (plus external packages), I haven't heard of it used much "in the wild". It seems like you could good, professional software in Racket using its FFI, contracts systems, and other features. My university is heavily tied to the Racket language and I'm going to be doing some work for their team this summer. They are currently pushing for Racket's shining point to be metaprogramming, not in the usual sense with Lisp where you write a few macros for convenience/efficiency; they have a vision of programmers making heavy use of writing DSL languages to make programs easier to understand. I've attached a draft of a sort of manifesto / summary of the goals of Racket. It seems a lot of Common Lisp folks don't really like Racket, and I think this because Racket's aims are different from CL. I don't really blame them, Common Lisp likes tricks and short-cuts, while Racket prefers to do things "The Right Way", which sometimes leads to verbosity. Also, most CL folks despise the hygienic macro system, without really realizing what it is. Racket's macros are MUCH more involved than just Scheme's (syntax-rules ...). http://beautifulracket.com/
pop · 2017-04-13 20:31
picked up my scheme textboard project once again. going to work on making the management panel useful now
Splicer · 2017-04-13 22:51
>>158 That is some good stuff!
John Titor · 2017-04-14 01:20
>>130 these were up before kalyxgate
over · 2017-04-14 02:15
>>178 Thanks but I was actually the one who posted them here before kalyxgate, they describe the Ivory's predecessors but not the Ivory.
Yuki Nagato · 2017-04-14 06:47
>>100 It might be if you're willing to fork it and step in as the BDFL of the fork. The progenitor of the language strikes me as something of a crackpot. As someone who's put some effort into learning Shen, and no effort into learning Typed Racket, you're probably better off learning Typed Racket. Or maybe looking at one of the projects out there trying to make a Lisp/Haskell hybrid.
Y.T · 2017-04-14 07:43
>>150 > Common Lisp likes tricks and short-cuts, while Racket prefers to do things "The Right Way", which sometimes leads to verbosity. Can you actually give any examples of this? > Also, most CL folks despise the hygienic macro system, without really realizing what it is. Hygienic macros are less straightforward, often less powerful, and offer very little benefit for a lisp-n. Hygienic macros exist because of the shortcomings of scheme (lisp-1 and the original lack of any module system). I've yet to come across anyone who thinks that syntax-rules is the only scheme macro definer.
Faye Valentine · 2017-04-14 10:48
I'm learning CLisp. I've always been allured to it, and recently figured I'd give it a shot. So far, I've enjoyed the whole experience! Tonight, in particular, I've decided to tackle programmingpraxis.com's problems, and I am currently struggling with the first one. In particular, I don't understand why I'm getting the error I'm getting. The code is not complete (eg. floats won't work, I don't think) -- I'm approaching this iteratively/incrementally. So... hey! I'd appreciate some input on what's wrong with this code, both in terms of styling and logic. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Implement an RPN calculator that takes an expression like ;19 2.14 + 4.5 2 4.3 / - * which is usually expressed as ;(19 + 2.14) * (4.5 - 2 / 4.3) and responds with 85.2974. ; The program should read expressions from standard input and print the top of ;the stack to standard output when a newline is encountered. ; The program should retain the state of the operand stack between expressions. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; The stack that contains the numbers. (setq *stack* '()) ;; Adds stuff to the stack from an input string. ;; If the string is a parseable integer, parse and push it as an integer. ;; Otherwise, just push the string as-is. (defun calc-read () (setq *stack* (cons(if (integerp (setq *user-input* (read-line))) (parse-integer *user-input*) (*user-input*)) *stack*))) ;; Read the top of the stack. If it is an operator (+,-,/,*), pop it, then pop ;;the top 2 numbers, perform the operation, and push the result back. (defun calc-eval () (if (integerp (car *stack*)) (setq *stack* (cons (parse-integer (car *stack*)) (cdr *stack*))) (cond ; TODO: Just (car) the operator and "interpret" it as a function. ; This should become a one-liner. ((string= (car *stack*) "+") (setq *stack* (cons (+ (cadr *stack*) (caddr *stack*)) (cddr *stack*)))) ((string= (car *stack*) "-") (setq *stack* (cons (- (cadr *stack*) (caddr *stack*)) (cddr *stack*)))) ((string= (car *stack*) "/") (setq *stack* (cons (/ (cadr *stack*) (caddr *stack*)) (cddr *stack*)))) ((string= (car *stack*) "*") (setq *stack* (cons (* (cadr *stack*) (caddr *stack*)) (cddr *stack*)))) ) ) ) ;; Print the, uh, top of the stack, I guess. (defun calc-print () (princ *stack*)) ; (format t '*stack* "~C~C" #\return #\linefeed)) ;; Infinite loop! (defun calc-loop () (loop (progn (calc-read) (car *stack*) (calc-eval) (calc-print) ))) (format t "Let's get this show on the road!~C~C" #\return #\linefeed) (calc-loop)
Erik Johansson · 2017-04-14 10:54
>>208 Awww soykaf. Indentation got killed; here's a pastebin where it's preserved: /QNPtuAtW
Hiro Protagonist · 2017-04-14 11:01
>>208 >>209 Progress: The *user-input* inside calc-read should not be parenthesized, since it's not being evaluated. Whoops. More errors are popping, though. The struggle is real.
John Peters, You Know, The Farmer · 2017-04-14 17:03
I recently got into lisp due to SICP. At first, I found the syntax kind of unbearable, but I've grown fond of it. With that said, though, I occasionally get weird errors on DrRacket and have a hard time finding solutions to the errors. Case in point. In one of the exercises, SICP asks the reader to find a product that converges to pi. Here's the code for it: (define (product term a next b) (if (> a b) 1 (* (term a) (product term (next a) next b)))) (define (inc x) (+ x 1)) (define (pi-approx n) (define (inc x) (+ x 1)) (define (square x) (* x x)) (define (num-prod ind) (* (* 2 ind) (* 2 (+ ind 1)))) ; calculates the product in the numerator for a certain term (define (denom-prod ind) (square (+ (* ind 2 ) 1))) ;Denominator product at index ind ;;When I comment these two lines out, the code runs fine (define num (product num-prod 1 inc n)) (define denom (product denom-prod 1 inc n)) (* 4 (/ num denom))) ;;Resulting value (pi-approx 25) When I do #lang sicp in DrRacket, I get the error in pic related, but when I change it to #lang racket it works... What am I doing wrong?
(princ tripcode) -| · 2017-04-14 17:37
>>208 I've rewritten some of your calculator, but the CALC-EVAL function is entirely incorrect. (defparameter *stack* () "The global calculator stack.") (defparameter *commands* (make-hash-table :test 'equal) "The global calculator command set.") (defun calc-read (stream) "Read calculator input and commands." (let* ((input (read-line stream)) (integer (parse-integer input :junk-allowed t))) (push (or integer input) *stack*))) The reason you've errors in CALC-EVAL is because you're calling PARSE-INTEGER with an integer object. PARSE-INTEGER is intended for strings and the :JUNK-ALLOWED argument allows it to return NIL rather than signal an error. Notice that CAR and related functions don't print the stack or have side effects. My advice is to look into FUNCALL, APPLY, PUSH, and hash tables before trying to correct this program.
Wintermute · 2017-04-14 17:38
Just a heads up: The files linked in the OP aren't on the server anymore.
if · 2017-04-14 19:34
>>234 The way you're using define might be syntactically incorrect, depending on what scheme you're using (eg. sicp vs racket). See eg. http://stackoverflow.com/questions/20896471/decent-way-of-nested-definition-in-scheme Take a look at let, letrec and friends for local bindings (https://docs.racket-lang.org/reference/let.html) something like (define (pi-approx n) (letrec ((inc (lambda (x) (+ 1 x))) (square (lambda (x) (* x x))) (num-prod (lambda (ind) (* (* 2 ind) (* 2 (+ ind 1))))) (denom-prod (lambda (ind) (square (+ (* ind 2) 1)))))) (let ((num (product num-prod 1 inc n)) (denom (product denom-prod 1 inc n))) (* 4 (/ num demon))))) Not tested at all btw. That said, it has probably been 1-2 years since I last wrote anything in scheme, so I might be wrong :-)
Boris Grishenko · 2017-04-14 20:33
>>234 I'm not very experienced but I would say that's a bug in Racket's SICP language. Your example works fine for me in MIT Scheme, for instance. From https://groups.csail.mit.edu/mac/ftpdir/scheme-reports/r5rs-html/r5rs_6.html#SEC29: >the expressions in the body of the lambda expression will be evaluated sequentially So the num-prod and denom-prod definitions should be evaluated first. Perhaps submit a bug report?
John Peters, You Know, The Farmer · 2017-04-15 01:36
>>256 >Perhaps submit a bug report? Will do! What I might try to do going forward is either learn racket and try to program with it, or make sure I don't do anything *too* fancy with scheme and/or make sure I'm following the Scheme guidelines specified in the book. Thanks a lot, though! Really helped!
push · 2017-04-15 06:41
>>272 Sorry, I was wrong about it necessarily being a bug. I still think it is, but I suppose it's open to interpretation. There's an exception for internal definitions in R5RS: https://groups.csail.mit.edu/mac/ftpdir/scheme-reports/r5rs-html/r5rs_7.html#SEC46 So in compliance with R5RS, each variable is first bound to a fresh location, and only after that are the values of the definitions evaluated (and only after that are the values assigned to the variables). So #lang SICP (which is based on #lang R5RS) is true to R5RS here, while Racket is not. It seems that Chicken, MIT Scheme, and SCM don't conform here. Gambit appears to conform here. (I found SCM's noncompliance surprising as they say they're a mostly R5RS-conforming implementation. It appears they assign each variable immediately after evaluation, in reverse-order.) However, R5RS came out after SICP, so I think an SICP language should be based on the IEEE standard. Actually, as the language claims to be "ideal" for SICP, I'd argue that it should behave similarly to MIT Scheme (which the SICP lectures use), which uses the transformation on page 528 of SICP. Though this is just my opinion. The takeaway from this is to not use internal definitions that have values that reference variables being defined in the same scope, as implementations that are R5RS-compliant in this area will throw you an error. So in the end, I suggest for your example that you use what >>253 did, or equivalently just replace the last 2 defines with a let expression. If you do decide to keep with SICP I'd stick with the #lang SICP or use MIT Scheme (since they use it in the SICP lectures).
Chani · 2017-04-15 06:50
>>286 Speaking of IEEE, I don't suppose anyone here would have an IEEE subscription to upload a copy of the IEEE Scheme standard? While I don't have a use for it myself, I find it odd how there's no publicly available version online. Since SICP references it, I think it'd be nice for it to be available.
Marly Krushkhova · 2017-04-15 07:31
>>288 I have access to "IEEE Xplore", if that helps you at all. Searching for "Scheme" turns up a ton of unrelated results, though.
Sabo Engle · 2017-04-15 14:12
>>234 because obviously there's no variable with that name. If you want to use the num-prod function from line 29 you have to change it to something like (define num (product (num-prod 1) (inc n))) obviously you'll have to change the product function signature
Zhora · 2017-04-15 14:59
>>309 What? Scheme (and higher order languages in general) are perfectly fine with you passing functions as arguments. In this case, num-prod denotes the function by that name, while (num-prod 1) denotes the application of that function on the number 1. They are two different things.
progn · 2017-04-15 18:21
>>292 It's IEEE 1178-1990. I believe this should be it: http://ieeexplore.ieee.org/Xplore/login.jsp?url=/iel1/2279/4109/00159138.pdf
Backus · 2017-04-16 04:04
>>292 I had access to that back when I was in school and, IIRC, the files are watermarked. So, be careful not to get yourself Swartzed.
Acid Burn · 2017-04-16 04:29
In case anyone is interested, here are R[234]RS: ftp://publications.ai.mit.edu/ai-publications/pdf/AIM-848{,a,b}.pdf and R[01567]RS are linked here: http://www.scheme-reports.org/
John Peters, You Know, The Farmer · 2017-04-16 20:46
>>309 >>312 >>286 Okay, didn't have time to reply earlier, but the bug was solved by adding the word "lambda" on the definitions, as in (define (pi-approx n) (define (inc x) (+ x 1)) (define (square x) (* x x)) (define num-prod (lambda (ind) (* (* 2 ind) (* 2 (+ ind 1))))) ; calculates the product in the numerator for a certain term (define denom-prod (lambda (ind) (square (+ (* ind 2 ) 1)))) ;Denominator product at index ind ;;When I comment these two lines out, the code runs fine (define num (product num-prod 1 inc n)) (define denom (product denom-prod 1 inc n)) (/ (* 4 (/ num denom)) 1.0) );;Resulting value It was kind of interesting reading the reasons why it throws an error. Thanks for all the help!
Koos van der Merwe · 2017-04-16 21:07
>>318 I was able to get it using sci-hub.
Tequila · 2017-04-18 11:52
>>141 Thanks, this will help a lot
Bobby Newmark · 2017-04-20 19:32
How do you find functions in Common Lisp? Is there a good directory or something? For instance, I wrote this earlier, but there has to be a function in the stdlib for it: (defun all (f xs) (cond ((null xs) t) ((funcall f (car xs)) (all f (cdr xs))) (t nil))) I just don't know what to look for or where to look.
Nanashi No Gombe · 2017-04-20 20:35
>>552 You might want something like Quicklisp.
Nobody · 2017-04-20 21:08
>>552 your 'all' looks like every function which is in standard. I use hyperspec when I'm looking for something: http://www.lispworks.com/documentation/HyperSpec/Front/
Agent Smith · 2017-04-20 22:09
>>552 I either ask in the #programming channel on irc.lainchan.org or #lisp on freenode about a concept and there's usually a function for it, amusingly enough. APROPOS is also useful. It'd probably be useful for an apropos function to search through documentation as well.
The Oracle · 2017-04-21 02:02
>>552 http://clhs.lisp.se/Body/f_everyc.htm Yeah, it's not totally discoverable. But searching for "lisp <thing I want to do>" usually comes up with something relevant.
vector · 2017-04-21 03:43
Posting this here because I'm working in Guile Scheme, though this isn't really a Lisp-specific problem. I am writing a script that automatically updates, builds & installs some git repos. All of this is done with Guile's 'system call. Ideally I want to spawn a new process with an unprivileged user ID that owns the repo being updated. The exit code of that process would tell the main script (which is running as root) whether to install or not. My problem is that I don't know of a nice way to run something as another user. `sudo -u *user* ...` doesn't seem to load /etc/profile.d/, which has a lot of necessary env variable definitions. `sudo -u *user* -i ...` DOES load profile.d but basically starts a new shell in the user's home... which makes sense. So I can do something like: (let ((wd (getcwd))) (system (format #f "sudo -u ~a -i sh -c 'cd ~a && unprivileged-action'" *user* wd))) But this is convoluted as hell. I'm making a call to sh with 'system, which then uses sudo to call sh again, to cd back into the directory I'm in to do what I want. What I really want looks like this: (system-spawn "cmd ..." uid working-directory) -> returns exit code To this end, https://www.gnu.org/software/guile/manual/html_node/Processes.html seems like a start, but I have yet to read through all that. If anyone's done this before I'd appreciate if you shared.
Zuse · 2017-04-21 04:11
>>562 To be clear, I want the hypothetical 'system-spawn to be something more akin to "cmd ... &" in shell, but run command as some unprivileged user.
Hacker · 2017-04-21 08:02
>>552 Isn't that the same as doing (mapcar nil f xs) ?
word · 2017-04-21 08:08
>>566 Meant map. Accidentally mixed elisp and common-lisp. Anyways, see http://clhs.lisp.se/Body/f_map.htm
H.R. Giger · 2017-04-21 22:00
>>566 No, it checks a predicate holds for every element in a list. EVERY is what I wanted. > (map nil #'evenp '(2 4 6)) NIL > (all #'evenp '(2 4 6)) T > (every #'evenp '(2 4 6)) T
Hopper · 2017-04-23 16:54
The Under-Appreciated Unfold
Cat Mother · 2017-04-24 07:06
>>583 Ah. I missed that.
(princ tripcode) -| · 2017-04-26 18:13
All thanks to our Appleman1234 and a dogman8, I now have a copy of most of the last thread; a few posts from the very end are missing, by my recollection. I figured someone asides from myself may find it useful and so want it. >>30 As for this, the recent confusion and ruckus got in the way, even where my game idea falling flat for the longest time didn't.
JARGON · 2017-04-28 23:04
>UPDATE 2017-04-26: Updated this page to link to my new and improved version of the ANSI CL standard draft which now includes a pdf sidebar outline. >Below is a link to a build of the publicly available ANSI CL standard draft, which has been somewhat modified to include a pdf sidebar outline. The sidebar makes it much easier to navigate this 1200 page plus document! http://cvberry.com/tech_writings/notes/common_lisp_standard_draft.html
Neuromancer · 2017-04-28 23:39
Watson IoT with Common Lisp Using ABCL with Eclipse Paho for IoT integration via MQTT https://developer.ibm.com/recipes/tutorials/watson-iot-with-common-lisp/
Anamika · 2017-04-30 02:05
Why isn't there a lisp as small and easy to embed as lua?
Switch · 2017-04-30 02:24
>>818 picolisp
Nobody important · 2017-04-30 02:27
>>818 Look into Guile and Chicken Scheme.
Elliot Alderson · 2017-04-30 15:18
>>818 There are quite a few actually
Joe Bloggs · 2017-05-01 10:50
>>818 http://synthcode.com/scheme/chibi/
Spike Spiegel · 2017-05-02 03:42
Someone in one of the previous thread had posted a utility for creating a function that accepts an arbitrary number of arguments, ignores them, and then executes the body. I believe it was called 0lambda or something similar, and I found it immensely useful! I was reading through the Common Lisp Quick Reference today (http://clqr.boundp.org) and found a built-in function that does the same thing named 'constantly' on page 17. Reading through the reference is really quite nice, I'm finding that I've written my own version of many of the functions that are already in the language.
Knuth · 2017-05-02 05:38
In the late 70s and 80s Microsoft had a LISP http://www.edm2.com/index.php/MuLISP zip archive with binaries and lisp source here http://www.din.uem.br/ia/ferramen/monoparadigmas/lisp/implementacao/mulisp/mulisp86.zip if you don't have an old x86 machine you can run it in DOSBox
(princ tripcode) -| · 2017-05-02 19:30
>>868 >Someone in one of the previous thread had posted a utility for creating a function that accepts an arbitrary number of arguments, ignores them, and then executes the body. That was me and it was last thread. Here's the routine: (defmacro 0lambda (&body body &aux (args (gensym))) "A lambda of variable arguments that ignores all of them." `(lambda (&rest ,args) (declare (ignore ,args)) ,@body)) >I believe it was called 0lambda or something similar, and I found it immensely useful! That's nice to read; I'm glad you found it useful. >I was reading through the Common Lisp Quick Reference today (http://clqr.boundp.org) and found a built-in function that does the same thing named 'constantly' on page 17. You had me concerned that I'd forgotten about such a built-in before writing my own, for a moment. The CONSTANTLY is actually different from 0LAMBDA. According to the Hyperspec, CONSTANTLY could be defined thusly: (defun constantly (object) #'(lambda (&rest arguments) object)) >Reading through the reference is really quite nice, I'm finding that I've written my own version of many of the functions that are already in the language. Eventually, one builds a mental map of the language and develops a feeling for what is and isn't already included. With that said, routines that are very rarely used can easily be forgotten, yes.
Milner · 2017-05-02 20:28
>>868 >>884 In which cases would 0lambda be useful? Any examples?
(princ tripcode) -| · 2017-05-02 21:57
>>888 >In which cases would 0lambda be useful? Any examples? I designed it for cases in which I'm using an interface that wants a function accepting certain arguments, yet don't need these arguments. I suppose HANDLER-BIND is an example of such an interface. I also used it to define this function, which makes for a nice default predicate function in certain instances: (setf (symbol-function 'true) (0lambda "Return T." t))
Mitnick · 2017-05-03 22:12
>>868 >>888 In Racket this is "(thunk* ...)". It is the variadic analog to "(thunk ...)" which creates a 0-argument function with just a body. Thunks are useful for representing delayed effects (such as callbacks for when a UI button is pressed). thunk* is useful for when you want to create a thunk but you don't want to run into any issues of arguments being passed in that you don't care about. If you pass arguments to a function created with (thunk ...), it will error, since the thunk requires exactly zero arguments. This is not the case with thunk*. However, I find it easy enough to just write out the lambda myself. In fact, (λ () ...) is shorter than (thunk ...), and (λ _ ...) is shorter than (thunk* ...). Also, less modules need to be imported this way.
Neuromancer · 2017-05-10 22:16
There's a new webdev framework for Scheme >Artanis >A fast monolithic web-framework of Scheme http://web-artanis.com/
Lady Jessica · 2017-05-11 02:56
So I'm new to Lisp, and trying to get started with it. I am trying to find a Lisp compiler that I can use similar to g++ (for C++), in that, I can open Command Prompt, type "g++ program.cpp" and compile it. Is there something like this for Lisp? I've found gcl and clisp, but they just run their own environment. Thanks in advance!
Erik Johansson · 2017-05-11 09:51
>>1066 SBCL for Common Lisp, Racket for, well, Racket, Clojure, and there are several Scheme implementations too. >type "g++ program.cpp" and compile it. that is not how you do things in lisp. That edit-compile-run cycle doesn't exist in the lisp world. You lunch a REPL edit your code and compile it once, try something new on the repl and that's it. Only the new part is incrementally compiled. Sorry if my explanation is a bit messy, but any Lisp book or video on youtube will probably clear your doubts
Emmanuel · 2017-05-12 11:35
>>1066 Chicken scheme does what you want, and the ecosystem is pretty nice as well. There are other scheme implementations that do this but i think chicken is the most comfy.
Lukasiewicz · 2017-05-12 14:18
>>1066 There is "raco exe" for generating executables from Racket code.
Yuki Nagato · 2017-05-12 18:55
>>1066 SBCL supports a --script option, e.g. sbcl --script file.lisp
J.C. Denton · 2017-05-12 20:31
>>1066 What >>1110 is correct, if you want to actually compile to an executable that can be run on a system without sbcl you need (save-lisp-and-die "fizzbuzz" :toplevel #'main :executable t) But be warned, because you can use eval and stuff in lisp, it saves the ENTIRE lisp environment in the executable too, so it's like 80 megabytes even for a hello world. You can add :compression t to get it down to ~20 but at the cost of some startup time.
queue · 2017-05-12 21:23
>>1112 is there a way to strip away the debugger and all that?
⍕ · 2017-05-13 01:03
I just use roswell for generating CL executables.
Jet Black · 2017-05-13 02:11
>>1071 >>1102 >>1105 >>1110 >>1112 Thanks for the info! Raco Exe seems like exactly what I'm looking for! I was debating between learning Common Lisp or Racket first, so I guess I'll start with racket :)
Knuth · 2017-05-13 09:19
It's useful under some circumstances, but the write->complie->test loop is really not how lisp development is done. I suggest giving the REPL a try to start with unless you have some special use case.
Linda Lee · 2017-05-15 15:34
>>1113 This is called pruning. I know at least one of the proprietary Common Lisp implementations offer it; LispWorks calls this ``tree shaking'': http://www.lispworks.com/ Allegro may also offer this, but I'm not certain: http://www.franz.com/products/allegrocl/ With the condition system of Common Lisp, you don't actually want to strip away the debugger and whatnot. A Common Lisp implementation offers a very comfortable and high-level symbolic debugger and this is the interface generally used to allow for interactively deciding on recovery strategies in case of failure and other exceptional situations, although you could easily write your own, too. It's recommended that you distribute (Common) Lisp programs as their source code. Many Lisps offer FASL (FASt Load) files, which are representations of the source code that can be loaded without parsing and whatnot involved; Emacs calls these compiled files.
Aristóteles Amadópulus · 2017-05-18 09:45
In scheme if I want to make a list the best thing to do I have seen this far is (define atomlist ((lambda x x) 'atom 'and 'another 'atom)) what does ((lambda x x) ) do with whatever input it gets after it?
Unknown · 2017-05-18 11:33
>>1259 Apparently nothing, the syntax also seems to be incorrect... Shouldn't you just use one of those? (list 'atom 'and 'another 'atom) '(atom and another atom) (cons atom (cons and (cons another (cons atom '()))))
McCarthy · 2017-05-18 11:34
>>1261 You'd also have to quote when using cons, my bad.
swap · 2017-05-18 12:04
>>1261 Those dont work when I want to save the list itself as variable. I forgot to mention the putting it behind a variable part, sorry. what doesnt work for you?
Void · 2017-05-18 14:11
>>1263 Well they don't work because you're trying to redefine something, change the variable name. You can see that on the error log. I'm surprised that the lambda thing works, though. Interesting.
Lain Iwakura · 2017-05-18 14:15
>>1263 >>1264 I'm not at home to use Guile or Racket, so here's TinyScheme running those examples on my phone.
Neo · 2017-05-18 14:19
>>1263 I'm so stupid I forgot that I already defined l. holysoykaf im retarded I dont know why I read over that part, sorry.
Donna Hawthorne · 2017-05-18 14:28
>>1263 Let's break down the slightly confusing function here: (lambda x x). This produces a function that accepts any number of arguments (that's the first x here) and returns the arguments (the second x). When the procedure is called it converts the arguments you gave it into a list and stores the list in the binding x, and then finally returns x. When you call atomlist the anonymous function is evaluated producing the list of arguments. The above should answer your first question, but if you're just looking to make a list >>1261 provided several acceptable ways of doing that. Exactly why you're getting a redefined constant error here is beyond me; I didn't even know scheme had a way to define constants. Close out of your REPL and try again, but I'm curious so I'll ask, what implementation are you using? Disclaimer: I hardly ever use Scheme. A common lisp equivalent of what you're doing would be: (lambda (&rest x) x).
fsociety · 2017-05-18 20:54
>>1267 >Exactly why you're getting a redefined constant error here is beyond me; I didn't even know scheme had a way to define constants That language isn't Scheme but Racket. Racket has several differences from Scheme, but in this context "constant" probably means "value from DrRacket definition area". Defining a value many times e.g. in a REPL is perfectly fine and acts like Scheme: > (define x 1) > (define x 2) > x 2
hash table · 2017-05-18 21:40
>>1259 ...you should just use the (list) function.
Hagbard Celine · 2017-05-19 10:13
>>1259 You are supposed to use (lambda lambda lambda)
Tyrell Wellick · 2017-05-26 16:05
Are there good tools/libraries to write a compiler for a non-lisp language in either Common Lisp or Scheme/Racket?
Boris Grishenko · 2017-05-26 16:19
>>1282
Lain Iwakura · 2017-05-26 16:42
>>1460 Racket has a great environment for writing languages, even those that don't have a syntax based on s-expressions.
McCarthy · 2017-05-27 01:55
What do you guys think of LFE? Just started learning it and, even though I'm not that skilled with Erlang, it felt rock solid for being a Lisp that embraces immutability and pattern matching to the core.
Vasya Pupkin · 2017-05-28 18:16
Is there a Common Lisp guide for Schemers?
Gyula Kovacs · 2017-05-29 16:43
>>1499 it's not exactly what you asked but take a look at >>794
Molly Millions · 2017-06-01 02:28
Presentation about Lisp for building compilers. A C compiler for Super Nintendo written in Lisp. Apparently from the International Lisp Conference 2012.
SHODAN · 2017-06-01 09:22
Found a 100% genuine japanese lisptan that dances Caramelldansen, use with caution Source: http://lambda.bugyo.tk/cdr/mwl/
Unspecified · 2017-06-03 21:15
>>1565 After having implemented a small "compiler" using Common Lisp myself, I fully support the thesis of the slide; Common Lisp is a great language for writing compilers. The read function is a Gods send. It makes implementing parser downright trivial, i.e., just read the source code in and then just manipulate the resultant s-expressions.
let · 2017-06-03 21:16
>>1569 Someone in previous Lisp general threads translated quite a significant number of these comics. Are those translations lost forever?
cond · 2017-06-04 02:30
>>19 I think both "Land of Lisp" and "Practical Common Lisp" have sections for this purpose. I remember neither being particularly in depth but the projects were certainly interesting and they made lisp look convenient for web-dev.
The Phantom Phreak · 2017-06-04 15:12
>>19 Clojure is really popular. Check the third book on >>163 If you want to use Common Lisp you are a bit more limited in terms of libraries available, but there are some. Check https://github.com/fukamachi libraries and framework Caveman
Linda Lee · 2017-06-05 02:14
Guys, SBCL tells me that an adjustable one dimensional array with a fillpointer and element type of character that I allocated isn't of type sequence, even though pic related. I'm really confused.
Just another Random Lainon · 2017-06-05 18:43
>>1637 From what I see, this could be an issue with how INTERPRET-TAG is defined. It looks like it's using the symbol itself during macroexpansion. Post the definition here so I can check.
XERXES · 2017-06-05 21:28
>>1643 I figured it out, it turns out I didn't know much about macros. I thought of them as functions that eval what they'd return.
Ender · 2017-06-07 09:40
>>1461 I didnt understand why he said that thanks
H.R. Giger · 2017-06-09 17:30
Why did people do away with fexps? They're simple to wrap my mind around. They're just functions that don't evaluate arguments. You get to manually evaluate whatever you want. This simple thing is shockingly powerful. When I think about it, each clause of eval is just a function that takes unevaluated arguments. So defining fexps is like adding custom clauses to eval itself. What could be simpler than this? People replaced it with macros, some pattern-based things like Scheme's. What's the point really? I don't buy the "too powerful" argument. Why use Lisp then?
Nell · 2017-06-09 18:27
>>1701 Given what you said, doesn't quoting arguments in Lisp produce the same behaviour?
Project 2501 · 2017-06-09 18:36
>>1705 I suppose fexps produce equivalent behavior to normal functions that take quoted lists as arguments. The difference is you don't need to quote everything
Milner · 2017-06-09 23:05
Could someone explain to me why people use PicoLisp and NewLisp which are both lisp-like languages? They are both dynamically scoped and interpreted-only. What do they offer that you cant get in a normal Lisp dialect?
Sipho Nkosi · 2017-06-09 23:30
>>1709 Because they're awesome. You just need to check out the feature list of newLISP to see how different it is from CL and Scheme. Most notable to me is the memory management model.
Acid Burn · 2017-06-10 00:21
>>1710 I'll be interested if it's not GC
Lady 3Jane.. · 2017-06-10 01:36
>>1711 https://www.youtube.com/watch?v=S7nEZ3TuFpA
Agent Jones · 2017-06-11 02:02
Are CL arrays O(1) access?
Turing · 2017-06-11 02:25
>>1721 Offhand, I don't believe the standard addresses the efficiency of anything in the language. With that written, it's safe to assume that Common Lisp arrays are going to be optimized in that manner, yes.
Bobby Newmark · 2017-06-11 09:48
>>1721 CL arrays/vectors (random) access time complexity should be O(1), yes.
paradox · 2017-06-12 22:13
I'm reading through the SICP and I'm getting caught up on an exercise Excercise 1.11 asks you to write a linear recursive, and linear iterative version of the same function function f such that f(n) = n if n < 3 and if n >= 3 f(n) = f(n - 1) + 2f(n - 2) + 3f(n - 3) The linear recursive implementation is a walk in the park (define (f n) (cond ((< 3 n) n) (else (+ (f (- n 1)) (* 2 (f (- n 2))) (* 3 (f (- n 3))))))) The linear iterative however I'm having much more trouble wrapping my head around I looked it up at http://community.schemewiki.org/?sicp-ex-1.11 but honestly even seeing the implementation on the screen is still so confusing, I've re-read the descriptions of linear iterative processes a couple times now, and while I understand it in principle I just don't feel like I have a firm grasp on how to write one, is this normal? Should I just keep practicing? Or do I need to read up on mathematics, which has always been my weak spot, in order to properly understand the book.
Mentat · 2017-06-12 23:35
>>1755 Haha, you don't need mathematics to understand tail recursion. You just need to consider the expansion. In a non-tail recursive function, the call stack just keeps growing and growing with each recursion: (+ (f ...) (* 2 (f ...)) (* 3 (f ...))) (+ (+ (f ...) (* 2 (f ...)) (* 3 (f ...))) (* 2 (+ (f ...) (* 2 (f ...)) (* 3 (f ...)))) (* 3 (+ (f ...) (* 2 (f ...)) (* 3 (f ...))))) And so on. The difference with tail recursive functions is that you have to have to pass the computation so far to the next call and return the result at the end, rather than keep it for later. Reason about what the function does and consider *what changes* with each iteration. That exercise is quite hard and reasoning in terms of tail recursion instead of just plain recursion is already hard in itself, so don't worry if you get stumped. Just try to understand the solution.
Joey · 2017-06-13 10:57
>>1755 Your implementation is wrong, the parameters in the condition should be reversed. Read section 1.2.2 again, it's the same problem as the Fibonacci, but with an additional parameter and some multiplications mixed in. Based on `fib-iter` the solution should be: (define (f n) (f-iter 2 1 0 n)) (define (f-iter a b c count) (if (= count 0) c (f-iter (+ a (* 2 b) (* 3 c)) a b (- count 1)))) The trick is understanding the parameters to f-iter. Here's a trace of running (f 5): trace: (f 5) trace: (f-iter 2 1 0 5) trace: (f-iter 4 2 1 4) trace: (f-iter 11 4 2 3) trace: (f-iter 25 11 4 2) trace: (f-iter 59 25 11 1) trace: (f-iter 142 59 25 0) trace: 25 We know that the last parameter, count, is the remaining number of iterations. But what about the values of a, b and c? If you compare them to outputs of your f function, you will quickly notice that in iteration `i` the values are a = (f (+ i 2)), b = (f (+ i 1)) and c = (f i). Rewriting the trace with these we get: trace: (f 5) trace: (f-iter (f 2) (f 1) (f 0) 5) trace: (f-iter (f 3) (f 2) (f 1) 4) trace: (f-iter (f 4) (f 3) (f 2) 3) trace: (f-iter (f 5) (f 4) (f 3) 2) trace: (f-iter (f 6) (f 5) (f 4) 1) trace: (f-iter (f 7) (f 6) (f 5) 0) trace: 25 You notice the pattern? Hope this helps.
Hong, Guil Dong · 2017-06-14 09:23
Does anybody have experience with building their own lisp? basically I've started to learn scheme, its a lot of fun. I'm using "the little schemer" as starting point. It made me realize why lisp is called lisp and how lisp works (for a bit ofcourse not im still fairly new) rather. but creating functions like (define atom? (λ (x) (and (not (pair? x)) (not (null? x))))) (define lat? (λ (x) (cond ((null? x) #t) ((atom? (car x)) (lat? (cdr x))) ;I like this part since you use a function, before its defined, in itself (else #f)))) made me wonder how hard it would be to make a minimal barebones lisp and just design it from the start as a understanding project.
SHODAN · 2017-06-14 09:59
>>1784 Writing a small Lisp interpreter in another Lisp is very easy, in fact TLS ends with making you implement an interpreter for a subset of Scheme in Scheme.
car · 2017-06-14 16:21
>>1784 It's pretty easy. I've been slowly writing my own for several weeks now. The hard part is deciding what features you want it to have, and what has to be interpreted by the host and what can be written in the lisp VM itself, and what particular use-case your lisp might fill.
Spike Spiegel · 2017-06-15 08:47
>>1795 How are you writing it? built on another language with your own functions or do you like use C or C++ to write it?
Netrunner · 2017-06-15 21:42
>>1814 writing a simple interpreter in C with no libc dependencies, then rewriting it to be self-hosting with a JIT compiler.
Vasya Pupkin · 2017-06-17 01:04
>>1821 mmh cool, thanks for the info. gotta learn C some day, why not this way. just began to wonder after seeing this http://www.buildyourownlisp.com/contents
Colmerauer · 2017-06-17 14:23
>>1840 It's not a very good guide, you're better off figuring it out on your own, it's not at all hard.
Mitnick · 2017-06-17 16:28
>>1857 What about Lisp in Small Pieces?
Acid Burn · 2017-06-17 23:46
>>1862 I was actually going to mention that book. I haven't read it whole, but what I've read is very good imo. It presents scheme in terms of scheme which I think is a great rendition. Near the end I think it also implements a scheme->C compiler and one to bytecode. I really like that book so if you want to learn C just becuase of lisp, I'd rather read this one.
Hagbard Celine · 2017-06-18 15:52
>>1840 >gotta learn C some day The title might seem inappropriate but then you realise it is.
Tequila · 2017-06-18 21:28
>>1857 Mmmh as you wouldve recommended that second other book >>1862 pointed out I'll just read that. thanks both. >>1884 I'll look at it thanks man
Roy Batty · 2017-06-18 22:46
And for those interesting in compilers check >>1550 I think there's also a book by the guy who wrote Chez Scheme about a Lisp compiler, but I might be wrong
Erik Johansson · 2017-06-19 12:46
I'm trying to understand how Chicken Scheme works with C and I ended up with those two files: http://sprunge.us/UWPd?scm and http://sprunge.us/AeXE?c But I don't think it's the right way to do it. Can someone point me to resources/books that would help ? How would you manage dependencies in such a project ? I mean installing the right version of libcurl automatically for example. Also is this code even well structured ?
FILLER · 2017-06-19 16:48
>>1840 https://matt.sh/howto-c You should really avoid C if you can get away with it.
SHODAN · 2017-06-19 17:23
>>1904 My impression was that you'd treat a Chicken Scheme project similarly to a C project (Makefiles, no dependency management). Your code looks fine, but I'm not sure if I'd read every single character of the file into a list.
Haruyoshi · 2017-06-21 20:01
>>1840 C is a great language, don't listen to >>1909 Learning C in depth along with assembler will give you a great understanding of a great systems language and low-level concepts.
Unspecified · 2017-06-21 20:26
>>1948 Do you know the reason why C compilers are so complex nowadays? It's because it maps very poorly to CPU instructions, which makes it anything but low-level. If you want to learn how the machine works, learn assembler, and if you want low-level use a high-level assembler. Just stop spreading this lie that C is somehow low-level because it has pointers and no GC and most OS are implemented in it and thus have native bindings to it; it's really not.
William Holtzer · 2017-06-21 20:45
>>1950 pretty depressing people just parrot the "C maps directly tot he CPU" meme. Maybe in the 70s and 80s, not so much since then. Definite sign of LARPers.
Yu-ichi · 2017-06-21 20:50
>>1950 >>1954 >Doesn't map very well to CPU instructions When what was said >great systems language and low-level concepts You guys sure are hostile to C to argue points that weren't even mentioned.
(princ tripcode) -| · 2017-06-21 20:57
While this discussion is interesting, this isn't a C thread. Someone should start one, although I suppose >>168 is generally filling that role. What have you programmed with Lisp, lately? I'm working on a tool I intend to attempt to release a prototypical version of by the end of this month, although this is merely a tool written in Lisp, as it was a good choice for this version, rather than a tool for or intimately related to Lisp.
Yu-ichi · 2017-06-21 20:59
>>1955 I wasn't responding to >>1948 so I'm not sure why you think I'm bashing it as a systems language. Its still pretty bad for that too, but now isn't the time for that.
Netrunner · 2017-06-22 06:54
>>1954 But it's still a good argument as to why C isn't really "low-level".
Jens Hansen · 2017-06-22 08:34
>>1909 >>1948 >>1950 >>1954 >>1955 ehhhh.. thanks for bringing some complexety, but atleast it saved me some work. I'll not learn C then or atleast for this project
FILLER · 2017-06-22 16:51
>>1970 I think you should actually learn C, even though I bashed it in the earlier posts. Almost all of the software you use on your computer was partially written in C in some way or another, so learning it is valuable if only to be able to understand the software that's using it. The concepts it uses can also be a good introduction to making you think about how algorithms and data structures are implemented. Just don't be fooled into thinking that C is the end-all systems language or that it's a ``portable assembler''; "systems" can, have, and should be written in languages other than C. As for the Lisp compiler; OCaml is often praised as a very good language for compilers, partly because of the language itself and partly because of the libraries and tools (ocamllex, ocamlyacc, menhir). Though of course it'd be much easier to use another Lisp. Racket has an excellent language development toolbox and some primitives for making a s-expression-based language.
Anonymous · 2017-06-23 01:48
I don't fuarrrking get this soykaf. CL-USER> (string-to-octets "hello") #(104 101 108 108 111) CL-USER> (octets-to-string #(104 101 108 108 111)) ; Evaluation aborted on #<TYPE-ERROR expected-type: (VECTOR (UNSIGNED-BYTE 8)) datum: #<(SIMPLE-VECTOR 5) {1003833F7F}>>. CL-USER> How the hell do I specific the type of the elements of an array in Common Lisp?
Neo · 2017-06-23 09:39
>>1980 Check the documentation for make-array
Ender · 2017-06-23 19:02
>>1980 when you use "#(104 101 108 108 111) it probably creates an array of fixnum not unsigned-byte but as you can see (octets-to-string (string-to-octets "hello")) works fine
William Holtzer · 2017-06-25 05:41
some specs on various Lisp Machines from the excellent book "Principles of Artificial Intelligence And Expert Systems Development" David W. Rolston, 1988 great book on expert system/lisp machine theory I picked up in a used book store today for $7, at the time published the author was a head engineer at the Electromagnetic Systems Laboratory which worked on Lisp Machines for the military
DEBUG-CONTENTS · 2017-06-25 05:53
>>2010 LMI Lambda emulator https://github.com/dseagrav/ld/ and required ROMs http://bitsavers.trailing-edge.com/bits/LMI/lambda/ Texas Instruments Explorer emu http://www.unlambda.com/lisp/meroko.page
Boole · 2017-06-26 05:43
wrote some lisp for this bioinformatics course on coursera #| PatternCount(Text, Pattern) count ← 0 for i ← 0 to |Text| − |Pattern| if Text(i, |Pattern|) = Pattern count ← count + 1 return count |# (defun pattern-count (text pattern) (let ((count 0) (textlen (length text)) (patternlen (length pattern))) (loop for i from 0 to (- textlen patternlen) do (if (equal (subseq text i (+ i patternlen)) pattern) (setf count (+ 1 count)))) count)) #| FrequentWords(Text, k) FrequentPatterns ← an empty set for i ← 0 to |Text| − k Pattern ← the k-mer Text(i, k) Count(i) ← PatternCount(Text, Pattern) maxCount ← maximum value in array Count for i ← 0 to |Text| − k if Count(i) = maxCount add Text(i, k) to FrequentPatterns remove duplicates from FrequentPatterns return FrequentPatterns |# (defun frequent-words (text k) (let ((table (make-hash-table :test 'equal))(max 0) (frequent-patterns ())) (loop for i from 0 to (- (length text) k) do (let ((pattern (subseq text i (+ i k)))) (setf (gethash pattern table) (pattern-count text pattern)))) (loop for key being the hash-keys of table using (hash-value value) do (if (> value max) (setf max value))) (loop for key being the hash-keys of table using (hash-value value) do (if (= value max) (pushnew key frequent-patterns))) (format t "(") (loop for cons on (sort (copy-list frequent-patterns) #'string<) do (format t "~a" (car cons)) when (cdr cons) do (format t " ")) (format t ")") t )) (defun opposite-nucleotide (x) (cond ((equalp x 'a) 't) ((equalp x 't) 'a) ((equalp x 'c) 'g) ((equalp x 'g) 'c) ((equalp x #\A) #\T) ((equalp x #\T) #\A) ((equalp x #\C) #\G) ((equalp x #\G) #\C) ((equalp x "A") "T") ((equalp x "T") "A") ((equalp x "C") "G") ((equalp x "G") "C") (t nil))) (defun reverse-complement (dna) (reverse (map 'string (lambda(c) (opposite-nucleotide c)) dna))) (defmacro check (form expected) `(format t "~:[FAIL~;pass~]: ~15,,,@a : ~15,,,a ~32,,,a~%" (equalp ,form ,expected) ,form ,expected (quote ,form))) (check (opposite-nucleotide "a") "t") (check (opposite-nucleotide "t") "a") (check (opposite-nucleotide "g") "c") (check (opposite-nucleotide "c") "g") (check (reverse-complement "AAAACCCGGT") "ACCGGGTTTT") I'm probably doing everything wrong and I don't feel very F U N C T I O N A L because im using setf a lot but it works well enough to pass their little exercises. I'm also trying to implement a scheme in c++ but I'm struggling.
Chan Siu Ming · 2017-06-26 20:59
>>2021 in case you like bioinformatics, this book uses Common Lisp. It's the first edition tho, I couldn't get my hands on the second one
Aristóteles Amadópulus · 2017-06-27 23:14
>>2021 jesus christ
push · 2017-06-28 09:38
will your lisp improve if you learn Lambda calculus? will it improve your thinking as overall people who like lambda calculus, use it, or have just learned it somewhere along their way. what is your opinion on it and recommending it to others.
Special Agent Bob · 2017-06-28 09:52
>>2045 btw source is "Lisp in small pieces" for the books mentioned check out https://ilammy.github.io/lisp/z1_bibliography.html
dup · 2017-07-08 12:39
What are some ways to get clisp to communicate with python?
Arisu Mizuki · 2017-07-08 14:03
>>2045 In my opinion, looking at the actual lambda calculus isn't really helpful other than as a jumping off point for a journey into type theory or to have an easier way to prove the Turing completeness of some language or system. If that's not what you're looking to do, it will only serve as entertainment (nonetheless interesting at that). If you've ever seen higher-order functions, there won't be anything new for you to see.
John Peters, You Know, The Farmer · 2017-07-09 00:26
>>3 I'm trying to install the 'darkmatter' package that's currently on HackerNews (apparently, it's a neat Common Lisp environment), but I'm having a bit of trouble actually getting it to work... Am I doing anything wrong? (Article where the screenshot is from is here:https://medium.com/@cddadr/darkmatter-the-notebook-style-common-lisp-environment-d6cff805f22e)
Hitomi · 2017-07-09 09:48
>>2239 It could be that PATH was not setup correctly. The installer did give a warning about that. Try if you can execute the binary directly. The screenshot says where it was installed. Try the following command: ~/.roswell/bin/darkm
pentashift · 2017-07-10 08:05
Just started learning common lisp this week. Coming from just enough programming experience to get by has made it quite the fun task. I just finished writing my first little macro (a implementation of XOR because I am running SBCL) and got super excited when it worked. Needless to say it's been a long time since I enjoyed programming this much where even such a minimal milestone has made me this proud. Coming from a pure python/ruby background into this has truly opened my eyes about the purity and elegance of this style of programming.
The Oracle · 2017-07-10 12:39
>>2259 Should XOR be a macro though? Unlike and/or it doesn't short circuit and you have to evaluate every input. So it should probably be just a pure function of its inputs, unless you want it to evaluate the arguments in a custom order (the standard defines the order of evaluation of arguments to a function as left to right like prog). Writing a macro that just implements a function is a nice exercise though. It can also be fun to play around with inputs that have side effects like printing to see whether it gets called multiple times.
Splicer · 2017-07-10 12:44
>>2259 Btw, reimplementing short-circuiting and/or macros is also a great macro-writing exercise if you haven't done that yet.
pentashift · 2017-07-10 18:39
>>2260 Yeah, it was more of an exercise than anything I would use in the day to day. Would be way easier to implement as a pure function and probably be nicer to look at. >>2261 Thanks for the suggestion, I'll have to try that out.
Spike Spiegel · 2017-07-15 09:32
Is Lisp a good language for creating artificial life?
God · 2017-07-15 14:34
>>2361 Provided you have The Flood available for garbage collection, it should go swimmingly.
Spike Spiegel · 2017-07-15 19:59
>>2364 I see. Thanks!
Apoc · 2017-07-15 23:51
>>2361 The Land of Lisp book has a chapter on an evolution simulator. Generally I'd say Lisp lends itself well because H O M O I C O N I C I T Y so you can use actual code for the chromosomes. >>2364 I see what you did there
Sabo Engle · 2017-07-16 15:33
Does someone please know of a simple IDE that I can just download without having to register via e-mail?
Sabo Engle · 2017-07-16 16:59
>>2386 Emacs
Iverson · 2017-07-16 18:46
>>2391 >Emacs Isn't that just a text editor?
Marly Krushkhova · 2017-07-16 20:01
>>2394 > Just a text editor Whew lad
Meddler · 2017-07-16 20:26
>>2386 https://www.mytrashmailer.com/
Frank Garza · 2017-07-17 00:10
>>2394 It's much, much more than that.
Bobby Newmark · 2017-07-17 03:32
>>2394 It can do all that a traditional IDE and much more. For concreteness, Emacs is THE Lisp IDE. It is itself written in Lisp (for the most part) and it has plugins for Lisp development. You have facilities to test your code live, compiling directly from your source file into a live REPL, with facilities to aid tracing and debugging. There is also a mode for editing lisp files more efficiently than treating it as just text. And one of the things people usually seek in an IDE is autocomplete. As it turns out, Emacs has plugins for autocomplete for Lisp and nearly every language in existence. And it's Free
Project 2501 · 2017-07-17 09:25
>>2401 >>2402 I see. Is there a way to make EMACS not look like some kind of MS/DOS-shell? I'd like it too look like any Windows before 10.
William Holtzer · 2017-07-17 10:36
>>2407 It has tons of themes as well.
Masami Eiri · 2017-07-17 15:53
>>2407 spacemacs has a big gtk gui or something but it's slow as hell
Project 2501 · 2017-07-17 17:37
>>2418 spacemacs does UI stuff entirely inside the emacs VM. It looks nicer.
Masami Eiri · 2017-07-17 19:18
How do I get emacs to compile with my SBCL?
Wintermute · 2017-07-17 20:05
>>2394 And a feed reader, mail client, music player, PDF reader, calendar/scheduler etc. >>2407 Something like powerline (https://github.com/milkypostman/powerline), smart mode line (https://github.com/Malabarba/smart-mode-line) and a fancy theme (see e.g., https://emacsthemes.com/) should do the trick.
array · 2017-07-17 22:07
>>2426 they are two completely different and independent software
Project 2501 · 2017-07-18 01:27
>>2426 To expand on what >>2431 said, emacs is mostly written in emacs lisp, not the common lisp that sbcl uses
let · 2017-07-18 11:47
>>2434 >>2431 Right, of course. I was wondering if it was possible to use a custom compiler for the editor.
Cereal Killer · 2017-07-19 21:26
>>2428 Thanks!
Crazy Jake · 2017-07-20 00:43
>>2436 Emacs itself is the Lisp compiler/environment (albeit a quirky one is a lot of ways). At its core the editor is not much more than said environment written in C and a basic `buffers of text' interface. Almost all the editing and other functionality and is written on top in Elisp, this is the main reason Emacs remains completely unsurpassed when it comes to customisation.
Fred Nurk · 2017-08-09 07:11
So, what Lisp programs have you all been writing lately? My primary efforts have gone to a decidedly unlispy program that's expected to be loaded in its own environment; in this case, Common Lisp is merely the implementation language I decided on using, primarily for the I/O primitives that my other choice lacked. A more casual but still good development is a Common Lisp library I'm writing and using often. It's a very Lispy program and I'm still developing it as I continue to use it for more of its intended purposes. Once I finish these two, I'd like to develop a minimal graphical interface program related to the former program mentioned. I'm mostly aiming for extremely small compiled size, so I'm considering using Chez Scheme; do any of you have any suggestions? I'd really rather this simple interface program be as small as possible, but it looks like I'll be unable to get it that low without digging through X11 internals I'd rather avoid in languages I dislike.
Just another Random Lainon · 2017-08-12 06:38
I wrote this helping macro. Someone might find it useful. https://github.com/ReinUsesLisp/axes
Tyrell Wellick · 2017-08-12 12:14
>>2888 Very helpful here, thank you
Jane Doe · 2017-08-13 15:17
Starting from a (non-lisp) work project, I'm developing a tool to generate random data following a template, currently a specific json layout, but once that's working hope to fully support Avro schema definitions.>>2893
Hououin Kyouma · 2017-08-18 13:28
>>2436 Just supply your own command to M-x compile and you're set.
t · 2017-08-28 21:56
Is there some guide about CL for Schemers?
Yet Another Lainon · 2017-08-29 19:38
>>3107 If you're reasonably good with Scheme, I'd suggest just diving in head-first and looking up things when you need them. I personally started with Common Lisp then went to Scheme, but I think it'll work fine the other way round as well.
John Peters, You Know, the Farmer · 2017-09-03 20:49
I'm currently going through "The Little Lisper" (they didn't have the Scheme version in my library) and am having trouble understanding currying. I have the following function (which removes the member "curry" from a list) (define Mrember-curry (lambda (l) (cond [(null? l) (quote ())] [(eq? (car l) (quote curry)) (Mrember-curry (cdr l))] [else (cons (car l) (Mrember-curry (cdr l)))]))) They then define the "curry-maker" function, which they use to redefine Mrember-curry (define curry-maker (lambda (future) (lambda (l) (cond [(null? l) (quote ())] [(eq? (car l) (quote curry)) (curry-maker future) (cdr l))] [else (cons (car l) ((curry-maker future) (cdr l))])))) (define Mrember-curry2 (curry-maker curry-maker)) How does this work? I don't really understand how, when applying the function curry-maker to curry-maker, as in [(eq? (car l) (quote curry)) (curry-maker curry-maker) (cdr l))] , leads to removing all instances of "curry" from a list.
Dozer · 2017-09-04 20:17
>>1957 just scrapers (with clojure). working on a scraper for okcupid so I can properly filter profiles for fembois and dickgirls.
setq · 2017-09-07 01:29
I've been going through SICP and I'm really enjoying Scheme as a language. What's a good next step in mastering Lisps? I'd be especially interested in resources that explore: - macros and metaprogramming - how to do it, what it's good for - practical applications (SICP is limited to algos/data structures/interpreters) - modern best practices and conventions. What's the most useful dialect to know? Seems like Clojure is fairly popular.
John Doe · 2017-09-07 02:10
>>3280 If you want to be productive in the real world: Common Lisp. On that topic, for intro into macro programming: "On Lisp" followed by "Let over Lambda" For getting things done beginner level: Practical common lisp, for more detailed getting things done: Common Lisp Cookbook
Motoko Kusanagi · 2017-09-07 02:45
>>3282 >LOL Had a PDF lying around from one of the sharethreads. I like it already :D.
(princ tripcode) -| · 2017-09-07 23:01
So, I was procrastinating on finishing a program I've been working on for the past few weeks and have been tweaking some parts of it in pursuit of this. Some functionality I'd originally thought I'd simply ignore was the ability for the program to exit when desired, but I later saw little harm in adding this functionality and it aided my procrastination. At first, I'd a simple LAMBDA with many of the most common cases, but later decided to pursue a library package, in part out of boredom. So, encompassing yesterday and today, I've been skulking through archives and whatnot, attempting to create a definitive such function; this is closer to archeology than programming, in my eyes. Currently, the ABCL, Allegro, CCL, Clasp, CLISP, CMUCL, Corman Common Lisp, ECL, Emacs-cl, GCL, Lispworks, MCL, MKCL, MOCL, OpenMCL, Poplog, SBCL, SCL, Ufasoft Lisp, WCL, and XCL implementations are supported, with support for Lisp Machine Common Lisps and Movitz being considered and whatnot, although it's questionable as to what this would or should do under these last two cases of implementations. The library name is SHUT-IT-DOWN, with nicknames QUIT and SHUTDOWN. This is, unsurprisingly, the smallest package I've ever created, containing one symbol, which is also the only exported symbol, QUIT, not even importing the COMMON-LISP package. The CC0 license was chosen for being reasonable towards such a small library and the email is currently invalid and provided mostly due to a licensing document suggesting the inclusion of an email. In comparing the differences across implementations and how one would generally use this, no attempt has been made to provide returning status codes to whatever host, as this was considered silly and relatively useless and not nearly common enough to expect to be present. It was mulled over that perhaps a :SIGNAL-ON-FAILURE keyword argument accepting a condition would be useful, but that this was quickly realized to be an overcomplication and equivalent enough to (PROGN (QUIT) (SIGNAL ...)). To use the jargon, an attempt at being transactional has been made. It is attempted that either quitting should succeed or the function should return, with no signaling of errors. Many implementations provide hooks and threads and whatnot and little attempt has been made to circumvent this; so, it's expected that preparations for a clean finish should be made when using this. From the perspective of a program that is portable and so adheres perfectly to the ANSI standard, sans the use of this package, I see little chance for an unclean finish that would violate this nature. Feel free to tell me what you think of this. I'll probably bug the Quicklisp maintainer to include this at some point in the next few days. If you notice an implementation is missing that I've not yet included, feel free to bring it to my attention. In particular, I don't seem to be able to find the MOCL documentation, even a notice that :MOCL is present in *FEATURES* was gleamed from an example program provided; documentation for Lucid Common Lisp is also sparse; I assume Ufasoft-lisp is similar enough to CLISP in this respect; I'm also perusing for KCL, AKCL, and BBN Lisp documentation, currently. A potential fix is to replace the NILs in this source with (CL-USER::QUIT), at least as a temporary solution.
sizeof · 2017-09-09 02:14
>>3207 Is there a git link to this anywhere?
bit · 2017-09-11 12:07
Portacle has reached 1.0: https://portacle.github.io - Seems like a good system to get someone quickly running a lisp environment. Though I think it's worth it to learn Emacs yourself, but people don't want to learn Emacs + a new language.
Lady 3Jane.. · 2017-09-12 06:33
So, looks like someone recreated a lisp-machine (again): https://www.youtube.com/watch?v=T1QlEJ-2Gho looks pretty nice actually
Unknown · 2017-09-12 14:15
>>3430 Not a Lisp Machine. That's StumpWM on top of Linux.
Backus · 2017-09-12 18:17
>>3436 true, but its trying to be as much of a lisp machine as possible.
Liet Kynes · 2017-09-12 18:46
>>2021 common lisp isn't functional also (defun opposite-nucleotide (x) (case x (a 't) (t 'a) (c 'g)(g 'c) (#\a #\t) (#\t #\a) (#\c #\g) (#\g #\c))) (defun reverse-complement (dna) (reverse (map 'string #'opposite-neucleotide dna)))
Naomi Nascimento · 2017-09-12 19:43
>>3440 >common lisp isn't functional Mostly true, but that doesn't mean you can't do functional soykaf in Common Lisp.
Neuromancer · 2017-09-13 04:32
>>3440 >common lisp isn't functional function composition is easier in CL than in haskell or ocaml, I'd say so functional programming != type theoretic compilers
Dox · 2017-09-13 06:36
>>3440 >common lisp isn't functional I see someone got drunk on Haskell kool-aid
Chan Siu Ming · 2017-09-13 16:32
>>3449 >function composition is easier in CL than in haskell or ocaml Have you ever used either of those? You'd be surprised.
藤原純一 · 2017-09-13 16:34
I just started trying out common lisp. It has very weird syntax but I kinda like it.
Shogun · 2017-09-13 19:47
>>3450 Common Lisp isn't any more functional than Lua or Ruby. Common Lisp comes with an assignment operator that supports C style rvalues. The 'when' and two argument 'if' are only useful for side effects. Besides lists, the built in data structures only support updating by changing in place. For example, you don't update a hash table by creating a new hash table based on an old one; you just update the old hash table in place. Common Lisp supports and encourages imperative programming and has almost no functional data structures built in. It should be pretty obvious that Common Lisp isn't a functional programming language.
Torvalds · 2017-09-13 20:00
There was once an academic conference series called the "LISP and Functional Programming Conference". This should suggest something to you about what the lisp community of the time thought about whether lisp was a functional language or not.
sizeof · 2017-09-13 21:15
>common lisp isn't functional I think this statement is factually correct. I don't think it implies anything positive or negative though. >One of the most common mischaracterisations of lisp is calling it a functional programming language. Lisp is not functional. In fact it can be argued that lisp is one of the least functional languages ever created... https://letoverlambda.com/index.cl/guest/chap5.html
Anamika · 2017-09-13 21:34
>>3460 yep, youre drunk on Haskell kool-aid alright >Common Lisp isn't any more functional than Lua or Ruby. Common Lisp comes with an assignment operator that supports C style rvalues. youre going to have to be more specific as to what a "C style rvalue" is because that could mean anything and sort of shows you dont really understand what youre talking about >The 'when' and two argument 'if' are only useful for side effects. Its implemented as a macro, its not a side effect >Besides lists, the built in data structures only support updating by changing in place. For example, you don't update a hash table by creating a new hash table based on an old one; you just update the old hash table in place. are you sure you understand what a hash table is? stop and think about what youre saying, a hash by definition generates keys, you cant make this in place >Common Lisp supports and encourages imperative programming and has almost no functional data structures built in. Lisp is entirely built on the list, the list is an immutable data structure. Which is why all functional languages like Haskell, Ocaml, Erlang, etc use lists and have list processing methods. If Lisp didnt care about immutability they would have just used the much easier to use arrays >It should be pretty obvious that Common Lisp isn't a functional programming language. its only obvious that you blindly drank Haskell kool-aid and believe the hype of 'pure functional programming' without really understanding what that is and that it doesnt really exist in Haskell
push · 2017-09-13 22:29
>>3466 >list >a real data strucutre lmao are you telling me that I can't change the car or cdr of a cons?
⍕ · 2017-09-13 22:31
Is there a more efficient way to find the first string in a string? [lisp] (defun first-string1 (buffer) (let* ((start (+ (position #\" buffer :test #'char=) 1)) (end (position #\" buffer :test #'char= :start start))) (subseq buffer start end))) (defun first-string2 (buffer) (with-output-to-string (str) (loop :for x :across (the string buffer) :as quote? = (char= x #\") :with get :if (and get quote?) :do (loop-finish) :if get :do (write-char x str) :if quote? :do (setq get t)))) The second is fastest so far.
Otto Normalverbraucher · 2017-09-13 23:11
>>3466 >youre going to have to be more specific as to what a "C style rvalue" is because that could mean anything and sort of shows you dont really understand what youre talking about rvalue has a specific meaning in programming. The way you didn't bother looking it up and accuse the other guy of ignorance is spectacularly poor form. I'm not >>3460 but I think what he said makes sense. Assignment goes against the functional principle of immutable state and rvalues go against the functional principle that programs are composed of functions. >are you sure you understand what a hash table is? stop and think about what youre saying, a hash by definition generates keys, you cant make this in place I think you should read the post you are responding to more carefully. He clearly said *updates* are done inplace, as opposed to creating a new table to way Clojure does. >Lisp is entirely built on the list, the list is an immutable data structure. No. They are the opposite actually. Lists are data structures which contain a pointer to the next element in the list. The whole point of a list is that you can dynamically add and remove elements without moving the existing elements around in memory. >its only obvious that you blindly drank Haskell kool-aid Stop strawmanning. I don't see anyone advocating Haskell. I don't even see anyone claiming that Lisp not being functional is a bad thing. It's not a bad thing it's just a fact.
Hououin Kyouma · 2017-09-13 23:34
>>3460 >>3466 >>3473 Looking back, I actually meant 'lvalue'. The cold medicine is having an effect.
word · 2017-09-13 23:57
>>3466 >youre going to have to be more specific as to what a "C style rvalue" is In C and other languages, the left side of an assignment is called the 'lvalue' and the right side of an assignment is called the 'rvalue'. (Note: I meant to say 'lvalue' earlier.) Scheme has an assignment operator, 'set!', but it can only change bindings. // C q = 3; a->b = 7; x[3] = 4; i.j = 2; // Common Lisp (setf q 3) (setf (car x) 3) (setf (cdr x) 4) (setf (get-foo obj) 10) (setf (get-hash 'foo *x*) 3) (setf (elt *y* 0) 5) //Scheme (set! x 3) ;; This is all you get. In C or Common Lisp, you can change a portion of a data structure in place. In Scheme, you cannot. >Its implemented as a macro, its not a side effect How they're implemented isn't important. What's important is how they're meant to be used. A one branch 'if' or 'when' operator very useful inside an expression. Their bodies need to use assignment or I/O to be useful. >are you sure you understand what a hash table is? stop and think about what youre saying You're missing the point. Racket, Haskell, and Clojure each have immutable associative arrays. Common Lisp does not. >Lisp is entirely built on the list, the list is an immutable data structure. Which is why all functional languages like Haskell, Ocaml, Erlang, etc use lists and have list processing methods. If Lisp didnt care about immutability they would have just used the much easier to use arrays This is wrong. Common Lisp has hash table and array data structures defined as part of its standard. Haskell has many data structures that aren't implemented in terms of lists.
Unnamed · 2017-09-14 04:17
>>3477 >Common Lisp has hash table and array data structures defined as part of its standard. variable names in Lisp are not really variables, they are pointers. so when you reassign a key in a hash table, you are just reassigning a pointer to new memory, there is nothing mutable, nothing is being overwritten. arrays in Lisp are syntactical sugar, its just numbered indexing to a list
(princ tripcode) -| · 2017-09-14 04:36
Common Lisp is certainly not a functional language in the modern sense of the phrase. It's functional in the sense that it allows functions to be manipulated, stored, etc. Common Lisp has no guarantee of tail call optimization and the looping primitives are TAGBODY and GO, which is imperative. Regardless, Common Lisp allows functional programming with discipline, just as with OO, imperative, and other paradigms. Lists are not immutable, as CONS cells can easily be changed directly by RPLACA and RPLACD. Arrays aren't implemented as lists and the expectation is that they're implemented in a way that gets the advantages of arrays over lists, such as fast indexing. As for hash tables, I'd imagine most implementations use some manner of arrays to implement them, but won't check; changing a key won't destroy the old value if its still accessible, but this seems relatively meaningless to mention. >>3469 I'd be interested in seeing you express this with a regular expression in the CL-PPCRE library and tell me if the resulting S-expression is more efficient than your approach.
progn · 2017-09-14 07:28
>>3481 You have no idea what you're talking about. >Lisp is, of course, famous for its list data structure, and most Lisp books, following the ontogeny-recapitulates-phylogeny principle of language instruction, start their discussion of Lisp's collections with lists. However, that approach often leads readers to the mistaken conclusion that lists are Lisp's only collection type. To make matters worse, because Lisp's lists are such a flexible data structure, it is possible to use them for many of the things arrays and hash tables are used for in other languages. But it's a mistake to focus too much on lists; while they're a crucial data structure for representing Lisp code as Lisp data, in many situations other data structures are more appropriate. http://www.gigamonkeys.com/book/collections.html
Nobody important · 2017-09-14 12:04
>>3460 >Common Lisp isn't any more functional than Lua or Ruby. >Lisp isn't more functional than two other inherently object-oriented programming languages Never go full retard.
list · 2017-09-14 13:37
>>3477 Scheme proper also has mutable lists and supports set-car! and set-cdr!, but they're barely used. Racket on the other hand doesn't and defaults to immutable lists. >>3487 What about Lua is inherently object-oriented? Sure, it does have objects (more or less), but Common Lisp also has an object system and it's definitely not implemented in a functional way. Scheme and the languages in the ML family are considered functional despite having imperative constructs because the idiomatic programming style is functional and mostly side effect-free. Common Lisp is very versatile and can be used to write both in a functional and in a procedural style, but the functions in the standard library lean more towards the procedural end, which makes it as much of a functional language as Javascript. Please inform yourself instead of just spouting stuff you've heard around.
Neo · 2017-09-14 13:39
>>3488 racket has mcons to create mutable cons cells and has set-mcar! etc
Debbie Charteris · 2017-09-14 13:47
>>3489 I know, it also has mutable hashes and other things I'm forgetting. >>defaults to immutable lists
Meddler · 2017-09-14 14:00
>>3490 hey didn't mean to insult, just to add up. To me it seems better that cons cells are seperated in birth, contrary to scheme. If you have cons you know it is bound to immutable and mcons mutable, so you can handle them taking in mind any side-effects that may occur later in your code. To me this seems a very good idea.
Zero Cool · 2017-09-14 14:34
I'm currently writing my own toy Lisp interpreter. It's mainly based on Scheme and Clojure. It currently supports data types such as integers, ratios, floats (all done using GMP, so they can't overflow), strings, symbols, lists, characters, booleans, and special value nil, which is not an empty list. The only functions implemented so far are +, -, *, / and eq? (works like equal? and is only called like that because it's shorter to type). The only special forms implemented so far are def (works like define), quote, fn (works like lambda) and if. There are no macros yet. Despite really bare-bones setup, it's already possible to write simple functions that operate on numbers, such as factorial: (def ! (fn (x) ((fn (f) (f 1 x f)) (fn (x y f) (if (eq? y 0) x (f (* x y) (- y 1) f)))))) The interpreter can do TCO, provided that the C compiler used to compile it does too, so it's possible to ask for factorial of really big values. For example (! 1000000) won't overflow the stack and will give you the correct answer (albeit after a bit of time has passed). The fact that I had to pass the function as an argument to itself in order to do a recursive call seemed inelegant to me. Since there is no let, much less letrec yet (though I'm probably going to settle on a single let that works like letrec, but binds its arguments sequentially like let*), I've come up with this solution, I think this is what one would call a fixed-point combinator. (def ! (fn (x) ((fn (f) ((f f) 1 x)) (fn (f) (fn (x y) (if (eq? y 0) x ((f f) (* x y) (- y 1)))))))) I don't think this project will go anywhere, but it sure is a lot of fun working on it.
Chani · 2017-09-14 18:56
>>3477 I dont think you really know what setf does https://stackoverflow.com/questions/869529/difference-between-set-setq-and-setf-in-common-lisp >>3468 >lmao are you telling me that I can't change the car or cdr of a cons? yes, thats what Im telling you, do you know what cons stands for? Its short for construct. Lisp doesnt change variables, it makes new ones, a very simple idea that no one here seems to get. >>3485 that quote supports everything I said
Hitomi · 2017-09-15 01:10
>>3491 I didn't mean to sound annoyed either. I think Racket's way is better as well, it is not that often that you need mutable pairs, and when you do it's better to signal so explicitly. The only downside is that it makes porting Scheme code that uses set-c(a|d)r a pain sometimes, but it's a better idea to try to minimize their use as much as possible anyway.
Dozer · 2017-09-15 03:18
>>3487 Common Lisp supports OOP far better than Lua does. Arguably better than Ruby. CLOS provides excellent support for OOP.
Tank · 2017-09-15 03:18
>>3493 If Lisp can't change data in place, how can the following work? (setf *print-circle* t) (defvar *x* (list 1 0 nil)) (setf (cddr *x*) *x*) (loop for i to 10 collect (nth i *x*))
drop · 2017-09-15 09:25
>>3510 warning: this code will lock up your computer
(princ tripcode) -| · 2017-09-15 13:21
>>3516 It shouldn't, unless *PRINT-CIRCLE* isn't set correctly and an endless expression is attempted to be printed: CL-USER> (setf *print-circle* t) T CL-USER> (defvar *x* (list 1 0 nil)) *X* CL-USER> (setf (cddr *x*) *x*) #1=(1 0 . #1#) CL-USER> (loop for i to 10 collect (nth i *x*)) (1 0 1 0 1 0 1 0 1 0 1) You've reminded me of a program I'd submitted here a time back, however, which I believe may be the simplest way to rather irrevocably lock a Common Lisp REPL: (tagbody loop (handler-case (loop) (condition () (go loop)))) Unfortunately, a standard infinite loop doesn't seem strictly possible, as there is potentially a small window of time between the undoing of the condition handler and its reestablishment during the GO control transfer. Also, environments such as SLIME and even the implementation itself may provide interrupting mechanisms outside the scope of program control. If someone can write a better infinite loop, please do. I'd considered nesting the condition handlers, but the window of opportunity still remains.
Roger Pollack · 2017-09-15 13:29
>>3516 If you forgot the first line, I could understand it locking up your REPL, but how the hell does it lock up your whole machine?
Gyula Kovacs · 2017-09-15 20:43
>>3521 The first line didnt look like it did anything so I left it out. I couldnt even close my console window when it went into a an infinite loop and could barely access my desktop interface, I was able to shutdown my computer.
progn · 2017-09-16 02:56
>>1795 How is your language going? What features did you end up choosing and leaving out? I was thinking of writing a Scheme myself because it's supposed to be a small language. Then reading the r7rs specification I saw that there is still a decent amount of features including somewhat esoteric ones (continuations, exceptions, dynamic-wind, parameterize, hygienic macros,...). Did you implement any of those?
Anonymous · 2017-09-20 13:50
Glad to have found the lisp general.
Cat Mother · 2017-09-20 13:51
>>3492 Progress update: -- special form let implemented as I described in the previous post; -- basic list manipulation functions -- list, head (works like car), tail (works like cdr), cons, append and null?; -- support for variadic functions -- they work quite differently from other Lisps in that if the name of the last argument of the function is ..., then any extra arguments get bound to it as a list when it's called; -- support for macros -- also quite different from other Lisps, they're first class citizens in my language much like functions; in fact, they differ from functions only in that the arguments are passed to them unevaluated and that the result they return is not used immediately, but evaluated first instead; -- some special forms useful with macros, namely quasiquote, unquote and unquote-splicing; -- some built-in reader macros for the former (the same as in Scheme, ' is quote, ` is quasiquote, , is unquote and ,@ is unquote-splicing). Now that macros are implemented I'll be able to write much of the rest of the language using them. For example, here's cond written as a macro (no fancy error handling yet): (def cond (macro (...) (if (null? ...) nil (let ((form (head ...))) (if (eq? (head form) 'else) (head (tail form)) `(if ,(head form) ,(head (tail form)) (cond ,@(tail ...))))))))
Meddler · 2017-09-21 19:13
Is land of lisp a good book to learn lisp?
Gyula Kovacs · 2017-09-22 02:51
>>3622 I'm currently using that book and it has cleared for me many of the concepts I didn't understand until now. I've written CL code for fun before, but I'm still a newbie, btw.
Colmerauer · 2017-09-22 07:22
>>3622 I personally found it hard to follow. The guy makes a text adventure game though out the whole book, I couldnt stay motivated to keep all that code in my head.
Just another Random Lainon · 2017-09-25 09:00
>>3613 Progress update: -- implemented special forms set! (contrary to what I wrote previously, it can be used to set the value of any variable, just like in Scheme), do (used to chain multiple expressions with side effects, provides proper exception handling, doesn't involve monads) and error (returns an exception, exceptions are just values that are treated specially by special forms, for example, if will return the exception if the condition evaluates to it, evaluating neither then-form nor else-form); -- reimplemented let using set!, the previous version had a few bugs, so I figured that I can implement it again as a macro instead of fixing them, here's the new definition: (defmacro let (bindings action) (if (null? bindings) action ((fn (binding) `((fn (,(st binding)) (do (set! ,(st binding) ,(nd binding)) (let ,(tail bindings) ,action))) nil)) (head bindings)))) -- implemented a few new macros and functions: and, or (they work the same as in Scheme, except that they return the first argument that's either truthy [in case of or] or falsy [in case of and] instead of plain boolean like in JavaScript), apply, apply-rest, reduce, filter, map, zip, transpose, max, max-by, min, min-by, rotate, all?, any?, none?, filter, split-at, drop, take, for, show and write; Most of the newly implemented functions are self-explanatory. apply-rest is a macro that takes a list with the function and initial arguments (has to be literal) and joins it with the other (must be quoted if it's raw, may be a variable). It's implemented like this: (defmacro apply-rest (call args) `(apply ,(head call) (append (list ,@(tail call)) ,args))) Functions like map take variable number of arguments where it makes sense, for example: > (map (fn (x y) (+ (* 2 x) y)) '(1 2 3 4) '(4 3 2 1)) | (6 7 8 9) for is a list comprehension macro. The first argument is an expression used to create the elements of the new list. The second argument is a list of variable bindings that look similar to those used in let, although the names are bound sequentially to the elements of the list. Any number of arguments that follow are the conditions that must be fulfilled for the new element to be included. For example, this Haskell code: Prelude> [x * 2 + y | x <- [1, 2, 3, 4], y <- [4, 3, 2, 1], x /= y, x > y] [5,8,7,11,10,9] is equivalent to this code in my language: > (for (+ (* 2 x) y) ((x '(1 2 3 4)) (y '(4 3 2 1))) (not (= x y)) (> x y)) (5 8 7 11 10 9) show[code] works like [code]display in Scheme and write is pretty much the same too: > (show "Hello World!\n" true) Hello World! nil > (write "Hello World\n" true) "Hello World!\n"nil Files are not implemented yet, so passing true as the third argument makes it write to stdout and return nil, and passing false makes it return a string with the representation. I'm planning to rewrite most of the part of the project written in C because the code is kinda soykaf.
Nguoi La · 2017-09-25 20:30
Where can I get a detailed explanation of the essential optimizations applied by high-performance Lisp implementations? Assuming the Pareto principle is true, 20% of the optimizations will get me 80% of the performance improvement enjoyed by these Lisps. I'd like to find out which optimizations are those and how to implement them.
Unknown · 2017-09-29 20:10
I (>>3537) am making a lisp in assembly with linux syscalls. The plan originally was to make a Scheme by making a basic language, then writing preprocessing passes in that language to do desugaring, macro expansion and optimization like replacing variable lookup by vector-ref and rewriting the program into a tree of closures kinda like they do in SICP (https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-26.html#%_sec_4.1.7) and finally bootstrapping the optimizer. At this point, I have a basic reader and printer, 64 bit integers, booleans, lists, symbols and functions. I've got define, set!, lambda, begin, if, quote, and a bunch of functions like cons, list, arithmetic functions on integers. Environment are lists of pairs. I still need to implement a garbage collector. Floats should be easy to implement. Byte-vectors, strings and vectors of large size will be more tricky since I'll need to think about how I allocate the memory. Run-time macros seem like a good idea now even though my language wouldn't be Scheme anymore. They'll let me get a usable language much faster without any desugaring passes. I might also implement user-defined special forms (fexpr) instead of macros. The disadvantages of run-time macros and fexpr is that eval is implicitly or explicitly called at run-time so there are optimizations that would be hard to do. (Actually this is a really interesting question. Is it possible to make a language that would have efficient first-class special forms? I guess for that we would need to make ASTs more complicated than just lists. Perhaps add some special syntax and make the reader resolve variable bindings...) >>3726 Treating exceptions just like values that are treated specially by special forms is an interesting idea. Does it result in the same behavior as "normal" (whatever that happens to be) exceptions?
Unspecified · 2017-09-29 21:41
I tried starting a new project in lisp but I'm having some difficulties I started with these steps, after running sbcl (ql:quickload :quickproject) (quickproject:make-project "somename") (ql:quickload :somename) and everything works. But then I leave sbcl, I change directory to the somename folder, start sbcl and when I do (ql:quickload :somename) I get an error, even tho I'm in the correct directory. Am I forgetting something?
⍕ · 2017-09-30 16:12
>>3830 As far as I can tell, yes. Of course there would be a problem if I forgot about exceptions in one of the special forms, but my Lisp doesn't have too many of those. I think functional Lisps are more suited for this approach because they're more "value-oriented". The way Haskell treats exceptions was an inspiration for me (although this is radically simpler, because it doesn't involve static types and monads).
Ender · 2017-09-30 17:37
>>3834 looks like you need to load quickproject first, after all its with that package that you created your project.
Lady 3Jane.. · 2017-10-01 20:10
>>3865 as far as I can see, quickproject only creates the project skeleton, ie the files package.lisp, projname.asd and projname.lisp
Jens Hansen · 2017-10-02 03:39
>>3830 >lisp in assembly with linux syscalls Hey I've been developing a similar project, some kind of low-level Lisp. I'm using freestanding C with my own x86_64 Linux system_call function. I made it so that the function is accessible from Lisp; it's one of the few procedures provided by the implementation. So I can, for example, mmap memory or files directly from Lisp. >I still need to implement a garbage collector This post walks you through it: http://journal.stuffwithstuff.com/2013/12/08/babys-first-garbage-collector/ I modified it so that it accepts pointers to usable memory blocks instead of calling malloc. When the implementation is loaded by the kernel, it allocates memory for a static array of objects; the garbage collector uses those until it's given more memory to manage. This allows the language to bootstrap itself without making any system calls. When it wants to allocate and free memory, it calls customizable Lisp functions. Default implementations are included right in the binary and simply mmaps or munmaps memory for the GC. >Byte-vectors, strings and vectors of large size will be more tricky since I'll need to think about how I allocate the memory. Yeah this is trickier. I've studied virtual machine implementations that store strings and byte arrays inline in their object structure, up to the size of the object structure itself. For bigger arrays, I guess I'll have to come up with some kind of pointer object.
Naomi Nascimento · 2017-10-03 18:24
>>3834 I fixed this issue, basically quicklisp only checks for projects in a specific location. Since I want to make it look for a project in the directory where I launched SBCL you have to add it to the list of directories to look for. this is achievable with this (add it to your .sbclrc file if you don't want to type it all the time): (pushnew *DEFAULT-PATHNAME-DEFAULTS* ql:*local-project-directories*) (ql:register-local-projects) Since emacs changes the current directory to the path of the file you're editing, this also works when you're writing code there and using slime
JARGON · 2017-10-07 18:09
Live streaming from Racketcon https://www.youtube.com/watch?v=et0C4ijed04
Koichiro · 2017-10-19 01:11
>>198 >Lisp/Haskell hybrid Do you know of any ? How is Lazy Racket ?
Guthrie · 2017-10-19 07:50
Hello, I'm a Lisp newb, and I want to customize my emacs. More precisely, I want to modify the LaTeX-indent-tabular function in the auctex package, because I don't like how the indentation of tabulars is done (I just want to change one value), but I don't want to modify the latex.el file because: 1. It's write-protected 2. I'm afraid the changes would be overwritten by a package update My first try was to copypaste the LaTeX-indent-tabular in *scratch*, do the change, C-j, but then I get an error message LaTeX-indent-tabular: Symbol’s function definition is void: destructuring-bind There should be something I'm completely missing.
Cypher · 2017-10-19 12:23
>>4447 There might be a variable for this: M-x apropos-variable RET LaTex indent RET ``destructuring-bind'' is from the cl.el packages. Ensure it's loaded via M-x load-library RET cl RET Useful: C-h f C-h v apropos
Technician · 2017-10-21 20:17
Has anyone here tried out Lux? It's a cool statically typed lisp that targets the JVM. There's a quick tour of the language here: https://luxlang.gitbooks.io/the-lux-programming-language Quick rundown: * It seems fairly academic compared to say, CL or Clojure. The focus is primarily on a really tiny core that can be used to build the rest of the language through macros, kind of like Scheme. (if ...) is a macro, not a primitive. The core of the language is pattern matching and lambdas. * The macro system is really powerful, and this is imho one of the most powerful metaprogramming systems I've seen for ML-like type systems. * The type system is also really tiny but lets you build on top of it. All types are values that can be manipulated in the language itself so that you can auto-generate new types programatically with a macro. It is much, much more powerful than Template Haskell and its ilk. * The equivalent of typeclasses can have multiple named instances for a single type that can be selected using macros, meaning you don't have to fiddle around with newtypes everywhere like in Haskell. * The compiler is just a monad (!) accessible from the language itself, which lets you implement arbitrarily complex reader macros. It seems really young at this stage and it has a few unique quirks, but as far as strongly typed lisps go, I really like it.
Lord Nikon · 2017-10-22 00:54
>>4492 thanks a lot anon, seems to be what I want
Drifter · 2017-10-22 09:51
>>4495 Welcome, it's a great language. The typical recommendations for people already familiar with programming are Practical Common Lisp by Peter Seibel and ANSI Common Lisp by Paul Graham. The former is a great demonstration of what the language can do. Otherwise there's A Gentle Introduction To Symbolic Computation by David Touretzky, which is more like a beginner's book using CL concepts.
Joey · 2017-10-22 19:11
>>4500 Hey, thanks. Can I use the 1990 edition of gentle introduction? The one that's free online? Or is the new edition that much better? I'm reading though SICP at the moment and translating Scheme to common lisp
Haruyoshi · 2017-10-22 22:22
>>4512 >Or is the new edition that much better? I have the 2013 edition in dead tree format and I've not been able to tell what's been changed from the 1990 version. Unless you're buying a physical copy, stick the free edition.
Emmanuel · 2017-10-23 11:42
Is Practical Common Lisp a good starter book? I just ordered it from Amazon earlier. Should be arriving today. I'll never get through all 1,400 pages of my C++ book either.
Miho Iwakura · 2017-10-24 17:04
>>4523 PCL is available for free online, you could have given it a try before buying it. It's a fairly good book, I just wouldn't recommend it to absolute beginners but I don't think that's your case. You might want to check >>3165 and >>149
Moore · 2017-10-24 20:09
>>4495 I learned Common Lisp by reading CLtL2 and then reading a list of differences with that and the final standard. Afterwards, I read several other Common Lisp books. I read Practical Common Lisp, but wasn't impressed with it. ANSI Common Lisp is a decent reference if I can't or won't access the Hyperspec or just need a quick detail; I always have my copy bookmarked at Appendix D, the language reference. I should probably bother to print and bind a copy of the Hyperspec and leave it at that, but I'd be better off printing and binding the Common Lisp Quick Reference instead, which is a resource I've largely neglected to use. This has me strongly inclined to do that now. Here's the Common Lisp Quick Reference: http://clqr.boundp.org/
Ein · 2017-10-25 07:39
How can I do 3D rendering and such with Common Lisp? Is it OpenGL? How do I get that up and working and also what's a good source to learn? I've only ever done really tiny stuff in OpenGL with C
Technician · 2017-10-25 11:00
>>4556 There's CEPL which provides a Lispy interactive interface to OpenGL. https://github.com/cbaggers/cepl Otherwise you're pretty much limited to FFI bindings to the C libraries, which can range from tolerable to rage-inducing.
Cowboy · 2017-10-25 16:34
>>4556 >>4559 Baggers has a youtube channel where he uses his library. https://www.youtube.com/watch?v=82o5NeyZtvw&list=PL2VAYZE_4wRITJBv6saaKouj4sWSG1FcS
Crash Override · 2017-10-29 04:45
So there's this new Scheme implementation called Cyclone which compiles to C. It looks like a decent compiled scheme from what I can see. Has anyone tried it? Is it good?
Donna Hawthorne · 2017-11-03 02:18
Oi
Cypher · 2017-11-03 07:06
I give up I genuinely don't understand why: (defun reverse-list (list) (dolist (i list) (reverse i))) always returns NIL What the actual fuarrrk What am I missing? I'm just trying to reverse every string in a list this shouldn't be hard
Tequila · 2017-11-03 08:02
>>4717 Where are the reversed strings going to? Think of dolist like a while loop. It doesn't return anything. So you need another variable that you put the reversed strings in. Fair warning, I don't really know CL I'm just guessing.
Fred Nurk · 2017-11-03 08:12
>>4718 >>4718 I had that same thought and for the record that same exact code but (print(reverse i)))) works and does print these things I'm trying to keep it as a list though I tried to do it with cons , even trying to cons it into the same list it came from even trying to recursively do it but no dice I guess I'm just stupid. I'll never get this stuff
Arisu Mizuki · 2017-11-03 11:32
>>4717 >>4718 is mostly correct, dolist doesn't return anything by itself, it's a macro that just does something for each item in a list. What you probably want in this case is the much more elegant mapcar which applies a function to each element in a list and returns a list of the results. It could be implemented as a do form like so - or with dolist and a let -, but I'd consider it bad style. (defun reverse-list (l) (do ((list l (cdr list)) (result '() (cons (reverse (car list)) result))) ((null list) (reverse result))))
Ivan Horvat · 2017-11-03 13:43
>>4724 Man. I wish I was smarter anon. I'm just getting into CL
pop · 2017-11-03 15:25
Whats a good resource to learn more about lambda expressions? I want to know exactly how it works and still feel kind of fuzzy on it
Sabo Engle · 2017-11-03 15:33
>>4727 Have you looked at exercism? I've done crypto-square, sieve and trinary in lisp and they were all a lot of fun. They give you test cases so you can make sure your solution works too
Gyula Kovacs · 2017-11-03 20:53
>>4728 SICP! People who are learning should start with Scheme instead of Common Lisp in my opinion. Or ever better, start with a modern "lisp" like Julia instead. The thing is old lisps, especially CL, have so many warts left over from decades ago (cdr and car and really everything related to list manipulation for programming purposes; macros are nice and all but macros are relied upon way too much in lisps) that it gets somewhat opaque to new programmers. I remember learning programming and jumping around from one programming language to another. CL was incredibly difficult to start with while Scheme was a lot easier. I actually ended up with Haskell, which I found to a much easier to learn programming in than Scheme, let's not even mention CL. If you are insistent on sticking to S-expressions, then I would recommend starting with a popular Scheme like Racket. If you just want all of the other goodies that lisps have like first-class functions and related higher-order functions, macros, homoiconocity, etc. with proper syntax, then I would recommend starting with Julia.
vector · 2017-11-03 20:58
>>4737 Also, if you are a new programmer, Elm is a fun language to learn.
The Fin · 2017-11-03 22:05
>>4737 does that mean CL is a bad first lisp? its what im already set up for and hav
Joe Bloggs · 2017-11-04 01:38
>>4740 Not that guy but I wouldn't recommend CL for beginners either. Get yourself The Little Schemer and start reading that.
Drano · 2017-11-04 02:08
>>4746 I already have that I just read it and do things in CL
Ivan Horvat · 2017-11-04 02:11
Clojure is also a decent option as far as lisps go. It's much less fractured than the Scheme community, and easier to pick up than common lisp. It also has a better standard library than most Schemes. The latter typically have separate (map ...), (vector-map ...), (hash-map ...) etc functions, while Clojure has a much smaller core of polymorphic functions that lets you write things generically over all collections.
BloodCat · 2017-11-04 03:40
>>4737 What is it about Scheme that you found more difficult than Haskell or Julia? Personally I think it's an excellent language to begin with and certainly helped me gain a better understanding of programming in general. >>4740 Common Lisp is excellent, and the most field-hardy of the family, but it is just that; common. CL was established in the 80s as a standardised dialect meant to replace the plethora of slightly incompatible Lisps around at the time. However, many organisations would only agree on a single orthodoxy if it inherited whatever idiosyncrasy their codebase relied upon. This caused much debate and a few big names to declare it an abomination, but ultimately resulted in the language we have today, laden with history as it. However, that history is also part of why I find the language fun and satisfying to use. It's a very organic Lisp, Scheme may be more elegant, but CL always has a variety of ways to reach any destination and interesting systems to play with along the way. I would not recommend trying to use CL for The Little Schemer or SICP though. The languages are similar enough that it can be done, but they have very different priorities and you will run into a variety of annoying issues, most notably the Lisp-1/2 divide and the treatment of macros. In addition, code that is good style in Scheme in very often not in CL, so those books will not be able to teach you how to use the latter in practice. The way SICP uses higher-order functions ends up being very ugly in CL, for example. All that said, definitely do read them, Lisp generally enjoys some of the best comp-sci literature there is, SICP and TLS are just the tip of the iceberg.
Koichiro · 2017-11-04 03:47
>>4756 >>4756 >>4756 I just want to learn more about common lisp. I really like it! I like you!
(princ tripcode) -| · 2017-11-04 03:49
>>4740 I'd recommend using Common Lisp, certainly since you already have the environment and whatnot set up. The Common Lisp COMMON-LISP package has a mere 978 symbols, encompassing the standard functions and variables and whatnot. Now, unlike Emacs Lisp and Clojure and other Lisps, Common Lisp and Scheme both have a wealth of implementations and books covering them. There's a Common Lisp and a Scheme for the JVM, as an example. The question is, perhaps, what you want to do with this. Doing something ``practical'' with Scheme will probably quickly force you into a single implementation, whereas Common Lisp is designed to be the common Lisp, with the majority of programs portable to any Common Lisp implementation without change, with the exception of pseudo-standard libraries that provide common interfaces over extended functionality, such as network access. So, what do you want to do with Lisp?
Sabo Engle · 2017-11-04 05:58
>>4761 It seems like you understand the idea of programming, but are not comfortable with forming an algorithm from a set of logical steps. It's also very possible that you've never found the right kind of material for how you learn. If you've never read it I strongly suggest trying The Little Scheme, it's a superb introduction to programmatic thinking in the form of a Socratic dialogue, and I think it's important to engage with it as a dialogue to get the most out of it.
Donna Hawthorne · 2017-11-04 06:24
>>4763 I think it's a syntax issue or something. I don't entirely understand dolist or how I can change it to do the thing It's just supposed to take a list, identify the even numbers and replace the even number with t and the non evens with nil I know its not correct in that dolist isnt giving me a list back so ill get nill but I just dont understand CL well enough
Nameless · 2017-11-04 19:32
>>4756 I'm just a sucker for syntax. Also, I could never remember the difference between car and cdr; like what's so hard about head and tail seriously. And Scheme and lisps in general rely way too much on macros. It's not that I think macros are super complicated but they can be opaque; just look at >>4761 struggling. Functions, especially pure functions, are very straightforward things. Another thing is that I find types to be extremely useful and I find it to remove a lot of confusion in terms of understanding code. >>4761 (from http://clhs.lisp.se/Body/m_dolist.htm) Look at this code ` (dolist (temp-one '(1 2 3 4) temp-two) (push temp-one temp-two)) => (4 3 2 1)` It's taking a list and reversing it. In each loop, temp-one is the i^th element in the list. And in each loop, temp-two is being modified. Without temp-two, i.e the third input to dolist, you are going to get nil as a result. E.g ` (dolist (temp-one '(1 2 3 4)) (+ temp-one 25)) => NIL` But, you can still modify variables inside the loop. So (setq temp-two 0) => 0 (dolist (temp-one '(1 2 3 4)) (incf temp-two)) => NIL temp-two => 4 You are modifying temp-two here. How would you put this in a function? Just do, (defun length-of-list (lst) (setq temp-two 0) ; => 0 (dolist (temp-one lst) (incf temp-two)) ; => NIL temp-two ; => length of list )
Colmerauer · 2017-11-04 19:35
>>4761 Programming is all about how you learn it. There is so much information out in the internet that it's easy to get lost. And all that information might not even be aimed at someone with your background and experience. You should really start with a beginners book (an actual book not the internet) like The Little Schemer like the other guy said.
Turing · 2017-11-04 22:40
>>4776 So why doesn't this work? (defun evenp-list (lst) '(dolist(tempone lst temptwo) (if(zerop(mod tempone 2)) (push t temptwo) (push nil temptwo))))