Earlier quoted context omitted.
The specification allows for this, yes. However, on some platforms (including linux glibc by default, I believe), malloc() never fails, but allocates virtual memory optimistically; the first you hear of an out of memory condition is when the system slows down due to paging, and the next thing you notice is when the OOM killer nixes a process. Of course, other platforms, especially embedded ones, behave differently.
Actually there is one reason for malloc to return NULL even with virtual memory, your process can run out of address space.
The Idea of Lisp
311–320 of 348 posts
Re: The Idea of Lisp
#312I wonder why lisp isn't as popular as say python for AI, ML, and stuff. I see these fields as having a strong academic tone, and it feels like racket or clojure could be bigger when it comes to that.
Well, it was. Specifically, Common Lisp was. But that language's standard was etched in stone in 1994 whereas languages like Python (where most deep learning user-facing code is done) continue to evolve. I think Python really took off for that because it already had quality and widely-used libraries for writing the code in Python and doing the work in a more efficient place (numpy, scipy). Clojure has one of those fo…
https://github.com/mikera/core.matrix
https://data-sorcery.org/
https://github.com/mikera/vectorz-clj
http://neanderthal.uncomplicate.org/
https://github.com/tel/clatrixRe: The Idea of Lisp
#313Earlier quoted context omitted.
I assure you that "malloc" and "free" don't "provide the illusion of infinite memory". Quite the opposite, in fact.
Challenge: Write a Turing complete machine using a finite number of registers and a state machine. One or all of the registers can contain a rational number of unlimited precision. (This has already been done, so if you are aware of the existing machines, you have to create a new one.)
Re: The Idea of Lisp
#314Earlier quoted context omitted.
It's the same thing. It's a type with only a single value.
`void` in C does not have a value. You can't make a variable and put a void in it because there is no such object as "void".
Re: The Idea of Lisp
#315Earlier quoted context omitted.
Same as in a higher-level statically typed imperative language: mutable arrays contained within larger dynamic buffers for amoritized constant-time append and prepend.
So it isn't really functional at all. It just hides the side effects behind a lot of complexity.
Re: The Idea of Lisp
#316Earlier quoted context omitted.
You may be interested in checking this out for inspiration: http://www.ccs.neu.edu/home/matthias/HtDP2e/ (It's the Intro to CS book used at my alma mater, teaching programming in Racket)
Tried doing some of that with High School kids -- I have to admit, at the beginning it was very difficult for them to wrap their head around the basic concepts in functional programming. The other issue was that the few syntactical rules and prefix notation, while great in the long term, required the kids to do a bit more of mental gymnastics for even basic things at the beginning, so that didn't help either. But man…
Re: The Idea of Lisp
#317Earlier quoted context omitted.
Clojure's an odd, unlispish language, at least for us Lispers and Schemers. CL is still very good at what it does: all current implementations have solved many of the problems you mentioned, and there are a lot of libraries that will run across implementations. CL is a beast, but clojure is a mess. Scheme is elegant, but has a radically different, more ALGOL mentality than CL, at least in some respects. Some of it is…
Could you explain what you think is wrong with Clojure? Maybe it's because I've spent far more time using it than CL, but I see Clojure as having a very consistent, well designed core. It's very opinionated in it's design, but it's a practical and pragmatic one. I don't see what's unlispish about it.
Lisp trusts the programmer to be responsible with mutability and not to abuse it. The trust is not misplaced; the sky doesn't fall.
Re: The Idea of Lisp
#318Earlier quoted context omitted.
That might not meet some expectations behind the word "properly".
Such expectations would have little to do with Lisp. Even one with a garbage collector can run out of memory. How quickly that happens and how it handles it is just a matter of how good of a garbage collector you have.
> How quickly that happens and how it handles it is just a matter of how good of a garbage collector you have.
It depends on the object size, how well objects are packed, and how much memory you have. Waste cannot be better than zero, so we have an upper bound on hitting OOM.
The lower bound (under non-compacting allocation) depends on the size ratio between the smallest and largest object. This is explored in paper by J.M. Robson (JACM 18, 416-423, [1971]) where Robson shows (IIRC, using only power of two block sizes, but arguing that the result is general) that an allocator client can be so contrived as to bring about the worst case whereby the heap consists only of the smallest objects, spaced apart just close enough that a request for the largest object can then be made, which fails. The memory utilization at that OOM moment is then the ratio between the size of the smallest and largest object. Robson's important argument is that an allocator has no way to defend against this problem. Regardless of its strategy for placing requests, the client can be contrived to tickle the worst case.
Fragmentation is not necessarily GC's fault; some objects just can't be moved. Objects which are opaque memory managed by a foreign library API pose an intractable problem in this area. There are good rationales for a non-compacting GC; non-compacting doesn't make it "bad".
Without GC, there is no lower bound on the amount of reachable data which exists under OOM. A tight loop which repeatedly calls cons will hit OOM.
Re: The Idea of Lisp
#319Earlier quoted context omitted.
Even Schemes can take a practical turn, e.g. Racket.
Racket isn't Scheme. It is its own dialect. That's why it's no longer called Scheme. At present, there are only a few Schemes that are practical: Chicken, Guile, Chez, and Gambit seem to be the big players, with Cyclone, Chibi, and Bigloo bringing up the rear.
It's also kind of funny that a handful of major, practical implementations is considered a low amount. Number of Python implementations? Between one and three, depending on definition. Number of Javas? 2 or 3 again. Number of Clojure implementations? One. Javascript? Half a dozen at most.
Seems to me like the problem is standardization between these implementations, not overall number.
Re: The Idea of Lisp
#320Earlier quoted context omitted.
Actually there is one reason for malloc to return NULL even with virtual memory, your process can run out of address space.
Or run out of room in the paging file. Your addressable memory cannot be larger than physical memory without a backing store.