Code Monkey home page Code Monkey logo

Comments (6)

alexgian avatar alexgian commented on May 31, 2024

Similarly for the unary functions, trig needs no be implemented

As it should be:

[sicmutils.env] > (- (up 'a 'b))
(up (* -1 a) (* -1 b))

needs implementation

[sicmutils.env] > (sin (up 'a 'b))

IllegalArgumentException No method in multimethod 'sin' for dispatch value: :sicmutils.structure/up  clojure.lang.MultiFn.getFn (MultiFn.java:156)

from sicmutils.

alexgian avatar alexgian commented on May 31, 2024

I should add that MIT scmutils does not actually define these generic operations, so if you have any objections, I am happy if they are left out for now, although I think they should be defined since they are simply scalar operations on a vector, albeit a "structure". Someone wanting to get a taster of structures as vectors would find it a whole lot more acceptable if they behaved predictably where one would expect them to do so.

In any case a user could simply

> (apply up (map (partial + 'c) (up 'a 'b)))  ==>  (up (+ c a) (+ c b))
       ;; or
> (vector->up (vec (map (partial + 'c) (up 'a 'b))))

So we are merely saving them the syntactic hassle.

from sicmutils.

littleredcomputer avatar littleredcomputer commented on May 31, 2024

I think we're scmutils-compatible here for the moment. My inclination is to leave it alone. (There's a tiny shortcut available, (s/mapr #(+ % 'c) (down 1 2 3)) to get (down (+ c 1) (+ c 2) (+ c 3)) (the advantage of mapr is you don't have to remember to wrap the structure back up after the mapping. Although it is recursive and will flood the operation down to all levels of the struct if it is deeper than a vector. Sometimes you want that, sometimes you don't; I should expose s/map as well). You can save one step in your second example by using (mapv) instead of (vec (map)). Or we could allow the arithmetic operations on things like you suggest. The downside of that is that adding a scalar to a vector might mean you are doing something wrong that you might like to know about rather than be surprised by a complicated expression somewhere down the line. So I lean toward letting the user write one of these snippets if that is what she wants.

from sicmutils.

littleredcomputer avatar littleredcomputer commented on May 31, 2024

Another trick from the undocumented realm:

(def u (up 1 2))
(s/same u (map #(+ % 'c) u))

from sicmutils.

alexgian avatar alexgian commented on May 31, 2024

OK.
I'll close for now.

from sicmutils.

alexgian avatar alexgian commented on May 31, 2024

I think a shimmed definition for map somewhere along these lines would be perfect:

(defn s/map [op struct] (sicmutils.structure/same struct (map op struct)))

Then the user would have both s/map and s/mapr to play with, nice, consistent and easily documentable...
Or you could call it "struct-map" or similar if you don't like "map", although I think "map" is perfect, it extends Clojure's map over sicmutils structures, just as one would expect.

from sicmutils.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.