News for hackers. Stuff that matters.
Re:Racket Language by cess11 on Sunday April 21, 2024 @01:38AM (#40103400)
"When I TAed, a lot of incoming 2nd year students didn’t know how to do for loops yet, which really set them back for basic algorithms."

They hadn't done simple recursive functions over lists? What had they been doing?

Been a while since I had to read introductory material for Racket (or any similar language), but as I recall functions with a base case exit and recursion is usually among the first things they teach.

Re:Racket Language by shawn_w on Sunday April 21, 2024 @02:32AM (#40103602)
Racket has a ton of different types of for loops for iterating over data structures etc. and collecting the results (or ignoring them). They're implemented under the hood using recursion but that's hidden from the user and it should be trivial to go from then to other languages. Maybe this class they're talking about didn't cover them?

https://docs.racket-lang.org/guide/for.html

Re:Racket Language by czhu12 on Sunday April 21, 2024 @02:46AM (#40103659)
it was indexing and mutating arrays / hashmaps that students had trouble with. Certainly a very different programming model than what’s presented in racket, with recursive iterations.

Of course with years of experience it’s easy to interpolate one from the other but these are students who’ve had 4 months of exposure to programming that have to jump from functional languages into operating systems and data structures and algorithms, all of which are taught with imperative languages

Re:Racket Language by cess11 on Sunday April 21, 2024 @05:17AM (#40104270)
I started with BASIC on C64-/VIC-style machines, then went on to dabble in C, C++, Java, Visual Basic, Delphi Pascal, PHP, before I came into contact with CL and Emacs. Recursion-iteration-equivalence was a mindblower for young me, suddenly I realised more ways to use it for problem solving in the algolians than I had seen before. If I had gone the other way around I'm sure I would have saved a lot of time.

This is surely a single point of anecdata, but it makes me suspect that it was more about how teaching was done than a 'functional vs. imperative' thing. I also suspect pointers and memory management to have been bigger hurdles than how to format code for iteration, unless the Racket course introduced techniques like quoting.

Re:Racket Language by spencerchubb on Sunday April 21, 2024 @01:58AM (#40103470)
Lisp variants only really have linked lists. So yes you can do recursion over them, but for someone who has never done a C-like language before, the arrays and for loops will take getting used to
Re:Racket Language by reikonomusha on Sunday April 21, 2024 @02:09AM (#40103508)
Lisp "variants" have lists, hash tables, multi-dimensional arrays, strings, bit sequences, streams, etc.
Re:Racket Language by aeonik on Sunday April 21, 2024 @07:00AM (#40104671)
Is it the case that all the cons cells at the base of the language are compiled into more efficient structures?
Re:Racket Language by lispm on Sunday April 21, 2024 @05:51PM (#40109548)
cons cells are not the base for vectors, strings and a bunch of other datastructures. Cons cells are mostly only used for nested lists or similar.
Re:Racket Language by aeonik on Tuesday April 23, 2024 @08:15AM (#40131035)
I guess I'm curious how the implementation of Vector works in Lisps. I thought it would be some sort of combination of Atoms and Cons cells.

I looked into the Racket Repo to find something, but had a hard time finding the code.

Re:Racket Language by Bogdanp on Wednesday April 24, 2024 @06:51AM (#40142819)
In Racket, a vector is a fixed-size contiguous array of memory. The values in each slot of a vector are tagged pointers so values like fixnums don't require any indirection to reach (i.e. they're unboxed). Racket also has specialized vector types for storing fixnums (fxvector), floats (flvector), strings (string) and bytes (bytes).

Other Schemes and Common Lisp have similar constructs. Just because a language is a lisp doesn't mean its primitives have to be implemented using cons cells.

Re:Racket Language by soegaard on Wednesday April 24, 2024 @07:24AM (#40143020)
As an example of other Schemes, here are the details of the representation used by Larceny (a Scheme):

https://www.khoury.northeastern.edu/home/lth/larceny/notes/n...

Re:Racket Language by kazinator on Wednesday April 24, 2024 @02:35PM (#40147976)
In a traditional-style Lisp which has atoms and cons cells, "atom" is not a specific type. It is a category which means "not a cons cell". Everything that is not a cons cell is an atom: symbol, string, number, character, vector, I/O stream, function, class object, ... Notice vector in there.
Re:Racket Language by lispm on Wednesday April 24, 2024 @03:04PM (#40148224)
The purpose of a vector in Lisp is to provide contiguous storage with integer index addressing and O(1) access time.

Cons cells are typically used to provide lists with O(n) access time.

Re:Racket Language by cess11 on Sunday April 21, 2024 @02:19AM (#40103544)
No they don't. The basic data structures in Racket are listed here, https://docs.racket-lang.org/reference/data.html . There are also specific array implementations in modules, like the generic array interface in the array module or arrays for math in a math module.

Recursing over a list is a way to learn how to implement for, while and friends. If you know this technique understanding for is just understanding a subset of what you are already familiar with. It can be used to iterate over an arrays as well as lists, e.g. with ranges: https://docs.racket-lang.org/reference/pairs.html#%28def._%2...

Racket can also be used to teach object oriented programming and programming with structs, if the aim is to teach patterns used in C-like languages generally it's not a bad fit. Well, except advanced stuff like pointer witchery. Though you could probably implement a teaching language that does it with arrays or the byte code directly if you wanted to. It might be a good way to improve on error messages for pedagogical purposes.

Re:Racket Language by pjmlp on Sunday April 21, 2024 @05:27AM (#40104305)
Only if stuck in 1950's Lisp.