Comments (4)
Can you give a code example of what you are trying to do?
from mal.
Yup.
For example,
(def! people '({"Name" "Homer" "Age" "43"} {"Name" "Bart" "Age" "8"}))
; This is easy and works. I would like to try rewriting it using ->
(map (fn* (p) (get p "Name")) people)
; This doesn't work as I don't think the map will return a partially applied function. Some languages do this automatically.
(-> people
(map (fn* (p) (get p "Name")))
; I could write a new function
(def! map-people (fn* (people) (map (fn* (p) (get p "Name")) people)))
; Then apply it like this and it works
(-> people map-people)
; I could try an anonymous function. But there must be an error here as I can't get this to work.
(-> people (fn* (ppl) (map (fn* (p) (get p "Name")) ppl)))
Is there a better way of rewriting my original map in the first example using ->?
from mal.
Threading macros and lambdas don't mix terribly well. In the case of map
, it's common to see ->>
for cleaning up an unwieldy expression the anonymous function is applied to. One can also mix both when needed.
from mal.
@wasamasa Thanks. I think I was misunderstanding the difference between thread first and last and confusing what was going wrong with my expression. I thought it had something to do with partial function application. I see now that I was just using the wrong threading macro.
Here is my working code:
(def! people '({"Name" "Homer" "Age" "43"} {"Name" "Bart" "Age" "8"}))
; This is easy and works. I would like to try rewriting it using ->>
(map (fn* (p) (get p "Name")) people)
; Here it is rewritten (works now)
(->> people
(map (fn* (p) (get p "Name"))))
; I wanted to chain filter and map together so I did that next
(->> people
(filter (fn* (p) (eq? (get p "Age") "43")))
(map (fn* (p) (get p "Name"))))
Thanks for your help.
Kerry
from mal.
Related Issues (20)
- VHDL: defmacro! doesn't modify existing functions HOT 1
- make "test^js^step0" fails -- Fatal error in , line 0 -- Check failed: result.second. HOT 1
- PDFs?
- Somebody should solve Rosetta Code challenges with mal
- Mal in Coq? HOT 2
- Apparently in step 3 'env' is a class or structure type, not an object HOT 2
- Questions on different design from lisp: Mal symbol do not use property lists? HOT 1
- Lots of unanswered merge requests HOT 1
- Why is quasiquote so complicated? HOT 3
- What with `` gensym '' HOT 2
- lexicial versus dynamic HOT 1
- Floats don't work in the python implementation. HOT 2
- Is #mal IRC channel still active? people seems tends to use discord now XD HOT 1
- Should `eval` use the top-level environment? HOT 1
- How is `cond` supposed to work? HOT 2
- Remaining impls to combine eval-ast/macroexpand into eval HOT 10
- common-lisp fails to build HOT 1
- Fix self-hosted test failures HOT 30
- Vala in self-hosted mode (i.e. running mal) has rare memory corruption (probably in throw/try/catch) HOT 1
- Fix powershell and elisp predicate/equality issues revealed by #665 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mal.