4 ms·
The main difference is that in lispy languages you wouldn't use the language itself to solve the problem. You'd extend it. I'd write a function that is (drop3-t
by schemy 6y ago
The main difference is that in lispy languages you wouldn't use the language itself to solve the problem. You'd extend it. I'd write a function that is (drop3-take5 test list) which does exactly what it says.
This might seem like huge overkill, but when the specs change and I need to set the start and stop from a config file I can easily refactor drop3-take5 into (drop-n-take-m n m test list), with a let around it to read the config.
drop3-take5 would look something like:
(define drop3-take5-list
(lambda (ls filter)
(define internal
(lambda (ls matches)
(cond
((null? ls) '())
(else
(if (filter (car ls))
(cond
((< matches 3) (internal (cdr ls) (1+ matches)))
((<= matches 5) (cons (car ls) (internal (cdr ls) (1+ matches))))
(else '()))
(internal (cdr ls) matches))))))
(internal ls 0)))
- vore 6y agoThis seems like an unsustainable approach: will you need to write these bespoke functions for any combination of behaviors you would need?
- schemy 6y agoLisp is about writing a dsl that solves your problem. It just happens to be an s-expression dsl. Exactly how it works depends on the problem domain. But in my experience a lisp dsl is much less brittle than trying to map the problem into a haskell program, especially with a changing spec. This is a bad example because it is so contrived to show off the strengths of haskell. As an example for the strengths of lisp: I wrote a logical dsl that adds a boolean dependent type system to scheme using macros. It's 400 lines long and copies all the bits from Idris I needed and it still feels like a scheme and is fully interoperable with regular scheme.
- bananaface 6y agoOk, now it fails - how are you going to interpret the stack trace?
- schemy 6y agoNot sure what you mean, it depends on the implementation. The cheapest cop out answer would be: use racket and step through until you reach the point where it fails. The IDE even gives you a nice handy list of the current continuation. I can trace it well less well in guile which is the usual scheme I use for daily projects but it's not something I've had huge trouble with on medium sized projects >10,000 lines.
- bananaface 6y agoThat's a helpful answer. Apologies if it seemed confrontational.