First time trying a Lisp - I do OOP spaghetti websites with C# for a living...

First time trying a Lisp - I do OOP spaghetti websites with C# for a living, it was the first thing I learned and stuck with it (self-taught and living in the second world)

Even doing trivial problems is giving me migraines, I've been stuck on this for 3 days:
4clojure.com/problem/31

This is a pathetic problem if you can use a variable that holds a state, but nope, everything is a constant. I guess I should be using reduce but have no idea what the reduce function should do, because everything is a constant.

Is it going to get better, /g?

Attached: Clojure_logo.svg.png (1200x1200, 89K)

Other urls found in this thread:

gigamonkeys.com/book/
twitter.com/SFWRedditVideos

(partition-by identity [1 1 2 1 1 1 3 3])


Persevere; great language.

>tfw can't even do question 2 on project euler

>websites in C#
But why?

NOT OP

can I do a lisp without touching clojure? Is clisp enough, should I try scheme/racket and if so which?

>what is ASP.NET

PS.
There is almost always a way to do something applicatively, i.e. by applying some function.

If you are asking this question, then Scheme.

Garbage, hence my question.

Yes
gigamonkeys.com/book/

err it almost works but I think that's the right idea?

(defun packseq (seq &optional (ans '()) (rep '()))
(cond ((null seq) ans)
((equal (car seq) (car rep))
(packseq (cdr seq) ans (append rep (list (car seq)))))
(t (packseq (cdr seq) (append ans (list rep)) (list (car seq))))))

fixed it

Attached: packseq.jpg (386x167, 22K)

>try to learn lisp via clisp
>studying for 3 months
>this code is still gibberish

There are too many keywords in lisps. I still can't do question 2 of project euler. I barely know how a lisp loop works

car is the first element of a list
cdr is the list minus car
cadr is the car of the cdr (2nd element)
cddr is the list minus the first 2 elements
etc.
So I'm passing the sequence except the first element every time I call packseq, then I'm saving a list of consecutive elements in rep until it stops repeating (then I append it to the answer).
I actually miss this car cdr bullshit when I mess with other languages now.

I started learning clisp 2 months ago by enrolling in an algorithm course, it's tough, professor asked us to implement mergesort, DFS, BFS, dijkstra in a language we had never touched before, of course I haven't fulfilled many assignments but the small stuff I can handle.

it's a fucking macro, which (i guess) means is a sepate entity, not even part of the syntax

(defun packseq (seq &optional (ans '()) (rep))
(cond ((null seq) (push rep ans) (reverse ans))
((equal (car seq) (car rep)) (push (car seq) rep) (packseq (cdr seq) ans rep))
(t (if rep (push rep ans)) (packseq (cdr seq) ans (list (car seq))))))
there. push is O(1) that's why I changed.

Not sure about that, have a comfy work experience with ASP.NET MVC & WebAPI

I've never wrote clojure before (only common lisp and scheme) but I'll give it a go.

(defn homework [list]
(map
(fn [v] (map (fn [i] i) v))
(get
@(reduce
(fn [data item]
(if (= (get @data :last-value) item)
;; add to last list
(let [last-list (first (reverse (get @data :lists)))
prev-lists (reverse (rest (reverse (get @data :lists))))]
(swap! data assoc :lists (apply conj (vec prev-lists) [(conj last-list item)])))
;; add new list
(swap! data assoc :lists (conj (get @data :lists) [item])))
(swap! data assoc :last-value item)
data)
(atom {:last-value nil :lists []})
list)
:lists)))

(println (homework [1 1 2 1 1 1 3 3]))

Lol as you can tell I'm use to common lisp

So in a nutshell the intended way of using Clojure is pipelining out-of-the-box functions and map/reduce/filter?

Try F#, its a lot easier and more practical than Clojure and it gives you access to interoperate with all your C# code

Just read