Search Results

Search found 7019 results on 281 pages for 'learning clojure'.

Page 9/281 | < Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >

  • Clojure: Testing every value from map operation for truth

    - by Ralph
    How can I test that every value in the collection returned by map is true? I am using the following: (defn test [f coll] (every? #(identity %) (map f coll))) with the anonymous function #(identity %), but I was wondering if there is a better way. I cannot use (apply and ...) because and is a macro. UPDATE: BTW, I am making my way through The Haskell Road to Logic, Maths, and Programming, by Kees Doets and Jan can Eijck, but doing the exercises in Clojure. It's a very interesting book.

    Read the article

  • Extract page from PDF using iText and clojure

    - by KobbyPemson
    I am trying to extract a single page from a pdf with clojure by translating the splitPDF method I found here http://viralpatel.net/blogs/itext-tutorial-merge-split-pdf-files-using-itext-jar/ I keep getting this error IOException Stream Closed java.io.FileOutputStream.writeBytes (:-2) This prevents me from opening the document while the repl is still open. Once I close the repl I'm able to access the document. Why do I get the error? How do I fix it ? How can I make it more clojurey? (import '(com.itextpdf.text Document) '(com.itextpdf.text.pdf PdfReader PdfWriter PdfContentByte PdfImportedPage BaseFont) '(java.io File FileInputStream FileOutputStream InputStream OutputStream)) (defn extract-page [src dest pagenum] (with-open [ d (Document.) os (FileOutputStream. dest)] (let [ srcpdf (->> src FileInputStream. PdfReader.) destpdf (PdfWriter/getInstance d os)] (doto d (.open ) (.newPage )) (.addTemplate (.getDirectContent destpdf) (.getImportedPage destpdf srcpdf pagenum) 0 0))))

    Read the article

  • Huge file in Clojure and Java heap space error

    - by trzewiczek
    I posted before on a huge XML file - it's a 287GB XML with Wikipedia dump I want ot put into CSV file (revisions authors and timestamps). I managed to do that till some point. Before I got the StackOverflow Error, but now after solving the first problem I get: java.lang.OutOfMemoryError: Java heap space error. My code (partly taken from Justin Kramer answer) looks like that: (defn process-pages [page] (let [title (article-title page) revisions (filter #(= :revision (:tag %)) (:content page))] (for [revision revisions] (let [user (revision-user revision) time (revision-timestamp revision)] (spit "files/data.csv" (str "\"" time "\";\"" user "\";\"" title "\"\n" ) :append true))))) (defn open-file [file-name] (let [rdr (BufferedReader. (FileReader. file-name))] (->> (:content (data.xml/parse rdr :coalescing false)) (filter #(= :page (:tag %))) (map process-pages)))) I don't show article-title, revision-user and revision-title functions, because they just simply take data from a specific place in the page or revision hash. Anyone could help me with this - I'm really new in Clojure and don't get the problem.

    Read the article

  • Clojure: Avoiding stack overflow in Sieve of Erathosthene?

    - by nixx
    Here's my implementation of Sieve of Erathosthene in Clojure (based on SICP lesson on streams): (defn nats-from [n] (iterate inc n)) (defn divide? [p q] (zero? (rem q p))) (defn sieve [stream] (lazy-seq (cons (first stream) (sieve (remove #(divide? (first stream) %) (rest stream)))))) (def primes (sieve (nats-from 2))) Now, it's all OK when i take first 100 primes: (take 100 primes) But, if i try to take first 1000 primes, program breaks because of stack overflow. I'm wondering if is it possible to change somehow function sieve to become tail-recursive and, still, to preserve "streamnes" of algorithm? Any help???

    Read the article

  • Good workflow with emacs+swank+slime+clojure?

    - by grm
    I just wanted opinion on good workflow using the emacs environment with clojure+swank+slime. I often find myself doing very repetitive keycommands and wonder if there is an obvious better way. I include swank with lein and start my project using lein swank from shell. Then I connect with emacs and do the correct use commands so that I can start to use (run-tests ). Then I do some coding and then want to test. To run the test I need to change buffer in emacs to the swank-repl C-x o, then I need to go to the prompt M-, then repeat the command M-p, then enter, maybe with an exception, then back to the code buffer and continue all over again with all the emacs commands. I find it a bit repetitive. I guess the solution would be to start hack on emacs and maybe add a shortcut for doing this repetitive task, but I would love to hear some suggestions because I can't be the only one who find this tedious?

    Read the article

  • Anonymous iterators blocks in Clojure?

    - by Checkers
    I am using clojure.contrib.sql to fetch some records from an SQLite database. (defn read-all-foo [] (let [sql "select * from foo"] (with-connection *db* (with-query-results res [sql] (into [] res))))) Now, I don't really want to realize the whole sequence before returning from the function (i.e. I want to keep it lazy), but if I return res directly or wrap it some kind of lazy wrapper (for example I want to make a certain map transformation on result sequence), SQL bindings will be gone after I return, so realizing the sequence will throw an error. How can I enclose the whole function in a closure and return a kind of anonymous iterator block (like yield in C# or Python)? Or is there another way to return a lazy sequence from this function?

    Read the article

  • Anonymous iterator blocks in Clojure?

    - by Checkers
    I am using clojure.contrib.sql to fetch some records from an SQLite database. (defn read-all-foo [] (with-connection *db* (with-query-results res ["select * from foo"] (into [] res)))) Now, I don't really want to realize the whole sequence before returning from the function (i.e. I want to keep it lazy), but if I return res directly or wrap it some kind of lazy wrapper (for example I want to make a certain map transformation on result sequence), SQL-related bindings will be reset and connection will be closed after I return, so realizing the sequence will throw an exception. How can I enclose the whole function in a closure and return a kind of anonymous iterator block (like yield in C# or Python)? Or is there another way to return a lazy sequence from this function?

    Read the article

  • Confused by "let" in Clojure

    - by Tom Dalling
    I just started playing with Clojure, and I wrote a small script to help me understand some of the functions. It begins like this: (def *exprs-to-test* [ "(filter #(< % 3) '(1 2 3 4 3 2 1))" "(remove #(< % 3) '(1 2 3 4 3 2 1))" "(distinct '(1 2 3 4 3 2 1))" ]) Then it goes through *exprs-to-test*, evaluates them all, and prints the output like this: (doseq [exstr *exprs-to-test*] (do (println "===" (first (read-string exstr)) "=========================") (println "Code: " exstr) (println "Eval: " (eval (read-string exstr))) ) ) The above code is all working fine. However, (read-string exstr) is repeated so I tried to use let to eliminate the repetition like so: (doseq [exstr *exprs-to-test*] (let [ex (read-string exstr)] ( (do (println "===" (first ex) "=========================") (println "Code: " exstr) (println "Eval: " (eval ex)) ) )) ) But this works once for the first item in *exprs-to-test*, then crashes with a NullPointerException. Why is the addition of let causing the crash?

    Read the article

  • Clojure warn-on-reflection and type hints

    - by Ralph
    In the following code, I am getting a warning on reflection: (ns com.example (:import [org.apache.commons.cli CommandLine Option Options PosixParser])) (def *help-option* "help") (def *host-option* "db-host") (def *options* (doto (Options.) (.addOption "?" *help-option* false "Show this usage information") (.addOption "h" *host-option* true "Name of the database host"))) (let [^CommandLine command-line (.. (PosixParser.) (parse *options* (into-array String args))) db-host (.getOptionValue command-line "h")] ; WARNING HERE ON .getOptionValue ; Do stuff with db-host ) I have a type hint on command-line. Why the warning? I am using Clojure 1.2 on OS X 10.6.6 (Apple VM). I assume that I do not get a warning on (.addOption ...) because the compiler knows that (Options.) is a org.apache.commons.cli.Options).

    Read the article

  • Delayed evaluation in Clojure

    - by StackedCrooked
    I'm having some trouble understanding how the delay macro works in Clojure. It doesn't seem to do what expect it to do (that is: delaying evaluation). As you can see in this code sample: ; returns the current time (defn get-timestamp [] (.getTime (java.util.Date.))) ; var should contain the current timestamp after calling "force" (def current-time (delay (get-timestamp))) However, calling current-time in the REPL appears to immediately evaluate the expression, even without having used the force macro: user=> current-time #<Delay@19b5217: 1276376485859> user=> (force current-time) 1276376485859 Why was the evaluation of get-timestamp not delayed until the first force call?

    Read the article

  • Getting all matches for a regexp on clojure

    - by Deleteman
    I'm trying to parse an HTML file and get all href's inside it. So far, the code I'm using is: (map #(println (str "Match: " %)) (re-find #"(?sm)href=\"([a-zA-Z.:/]+)\"" str_response)) str_response being the string with the HTML code inside it. According to my basic understanding of Clojure, that code should print a list of matches, but so far, no luck. It doens't crash, but it doens't match anything either. I've tried using re-seq instead of re-find, but with no luck. Any help? Thanks!

    Read the article

  • Is writing recursive functions hard for you?

    - by null
    I'm taking a computer science course now. I feel it is so hard compared to my polytechnic IT course. I can't understand recursive methods well. How do you manage to get your brain to understand it? When the recursive method returns back, my brain can not trace it nicely. Is there a better way to understand recursion? How do you start learning it? Is it normal that feel that it is very hard at then beginning? Look at the example, I'm very surprised how can I write this if it appears in exam. public class Permute { public static void main(String[] args) { new Permute().printPerms(3); } boolean[] used; int max; public void printPerms(int size) { used = new boolean[size]; max = size; for (int i = 0; i < size; i++) { used[i] = false; } perms(size, ""); } public void perms(int remaining, String res) { if (remaining == 0) { System.out.println(res); } else { for (int i = 0; i < max; i++) { if (!(used[i])) { used[i] = true; perms(remaining - 1, res + " " + i); used[i] = false; } } } } }

    Read the article

  • I want to make "stuff" on the web, is a BsC. in Computers necessary/overkill? [on hold]

    - by notypist
    I'm 24 and have a lead role in a major news outlet in my country, with a good pay and public image in the horizon. I hold a job that was previously held by people with 15-20 years of experience and considered one of the top 5 news anchors in my country. My passion though, is computers. The web, to be precise. I was a problogger at a very young age. I hacked my way through CSS and some basic HTML and PHP. But I want to move forward - I want to CREATE not just STRUCTURE things. Giving up the present (and especially the seemingly promising future) in my current industry is hard, my friends raise their eyebrows... I'm considering a BsC. in computer Engineering - but my stats are short of getting into a good university for this discipline. Plus, I'm not the best with math - although I do exceptionally well in statistics and other numbers that are more applicable to real life. I tried learning PHP through online websites, but that just "doesn't cut it" for me. Nope. So what are my options here? if I don't want to build hardware or and deal with overly-complex algorithmic but would like, for example - to build a well functioning iPhone and iPad app, or a SaaS, a startup...do I have to go the BsC. route? I don't see any option to get an "official" education in strictly "web" concepts and languages.. Note: I'm well off financially, so I'm doing this more to be able to create stuff, rather than get a job in a corporations. Although if I land somewhere high, that might be an option. But my main concern is getting the tools.

    Read the article

  • Mutation Problem - Clojure

    - by Silanglaya Valerio
    having trouble changing an element of my function represented as a list. code for random function: (defn makerandomtree-10 [pc maxdepth maxwidth fpx ppx] (if-let [output (if (and (< (rand) fpx) (> maxdepth 0)) (let [head (nth operations (rand-int (count operations))) children (doall (loop[function (list) width maxwidth] (if (pos? width) (recur (concat function (list (makerandomtree-10 pc (dec maxdepth) (+ 2 (rand-int (- maxwidth 1))) fpx ppx))) (dec width)) function)))] (concat (list head) children)) (if (and (< (rand) ppx) (>= pc 0)) (nth parameters (rand-int (count parameters))) (rand-int 100)))] output )) I will provide also a mutation function, which is still not good enough. I need to be able to eval my statement, so the following is still insufficient. (defn mutate-5 "chooses a node changes that" [function pc maxwidth pchange] (if (< (rand) pchange) (let [output (makerandomtree-10 pc 3 maxwidth 0.5 0.6)] (if (seq? output) output (list output))) ;mutate the children of root ;declare an empty accumulator list, with root as its head (let [head (list (first function)) children (loop [acc(list) walker (next function)] (println "----------") (println walker) (println "-----ACC-----") (println acc) (if (not walker) acc (if (or (seq? (first function)) (contains? (set operations) (first function))) (recur (concat acc (mutate-5 walker pc maxwidth pchange)) (next walker)) (if (< (rand) pchange) (if (some (set parameters) walker) (recur (concat acc (list (nth parameters (rand-int (count parameters))))) (if (seq? walker) (next walker) nil)) (recur (concat acc (list (rand-int 100))) (if (seq? walker) (next walker) nil))) (recur acc (if (seq? walker) (next walker) nil)))) ))] (concat head (list children))))) (side note: do you have any links/books for learning clojure?)

    Read the article

  • Appending and prepending to XML files with Clojure

    - by Isaac Copper
    I have an XML file with format similar to: <root> <baby> <a>stuff</a> <b>stuff</b> <c>stuff</c> </baby> ... <baby> <a>stuff</a> <b>stuff</b> <c>stuff</c> </baby> </root> And a Clojure hash-map similar to: {:a "More stuff" :b "Some other stuff" :c "Yet more of that stuff"} And I'd like to prepend XML (¶) created from this hash-map after the <root> tag and before the first <baby> (¶) The XML to prepend would be like: <baby> <a>More stuff</a> <b>Some other stuff</b> <c>Yet more of that stuff</c> </baby> I'd also like to be able to delete the last one (or n...) <baby>...</baby>s from the file. I'm struggling with coming up with an idiomatic was to prepend and append this data. I can do raw string manipulations, or parse the XML using xml/parse and xml-seq and then roll through the nodes and (somehow?) replace the data there, but that seems messy. Any tips? Ideas? Hints? Pointers? They'd all be much appreciated. Thank you!

    Read the article

  • Efficient Clojure workflow?

    - by Alex B
    I am developing a pet project with Clojure, but wonder if I can speed up my workflow a bit. My current workflow (with Compojure) is: Start Swank with lein swank. Go to Emacs, connect with M-x slime-connect. Load all existing source files one by one. This also starts a Jetty server and an application. Write some code in REPL. When satisfied with experiments, write a full version of a construct I had in mind. Eval (C-c C-c) it. Switch REPL to namespace where this construct resides and test it. Switch to browser and reload browser tab with the affected page. Tweak the code, eval it, check in the browser. Repeat any of the above. There are a number of annoyances with it: I have to switch between Emacs and the browser (or browsers if I am testing things like templating with multiple browsers) all the time. Is there a common idiom to automate this? I used to have a JavaScript bit that reloads the page continuously, but it's of limited utility, obviously, when I have to interact with the page for more than a few seconds. My JVM instance becomes "dirty" when I experiment and write test functions. Basically namespaces become polluted, especially if I'm refactoring and moving the functions between namespaces. This can lead to symbol collisions and I need to restart Swank. Can I undef a symbol? I load all source files one by one (C-c C-k) upon restarting Swank. I suspect I'm doing it all wrong. Switching between the REPL and the file editor can be a bit irritating, especially when I have a lot of Emacs tabs open, alongside the browser(s). I'm looking for ways to improve the above points and the entire workflow in general, so I'd appreciate if you'd share yours. P. S. I have also used Vimclojure before, so Vimclojure-based workflows are welcome too.

    Read the article

  • dealing cards in Clojure

    - by Ralph
    I am trying to write a Spider Solitaire player as an exercise in learning Clojure. I am trying to figure out how to deal the cards. I have created (with the help of stackoverflow), a shuffled sequence of 104 cards from two standard decks. Each card is represented as a (defstruct card :rank :suit :face-up) The tableau for Spider will be represented as follows: (defstruct tableau :stacks :complete) where :stacks is a vector of card vectors, 4 of which contain 5 cards face down and 1 card face up, and 6 of which contain 4 cards face down and 1 card face up, for a total of 54 cards, and :complete is an (initially) empty vector of completed sets of ace-king (represented as, for example, king-hearts, for printing purposes). The remainder of the undealt deck should be saved in a ref (def deck (ref seq)) During the game, a tableau may contain, for example: (struct-map tableau :stacks [[AH 2C KS ...] [6D QH JS ...] ... ] :complete [KC KS]) where "AH" is a card containing {:rank :ace :suit :hearts :face-up false}, etc. How can I write a function to deal the stacks and then save the remainder in the ref?

    Read the article

  • Improving my first Clojure program

    - by StackedCrooked
    After a few weekends exploring Clojure I came up with this program. It allows you to move a little rectangle in a window. Here's the code: (import java.awt.Color) (import java.awt.Dimension) (import java.awt.event.KeyListener) (import javax.swing.JFrame) (import javax.swing.JPanel) (def x (ref 0)) (def y (ref 0)) (def panel (proxy [JPanel KeyListener] [] (getPreferredSize [] (Dimension. 100 100)) (keyPressed [e] (let [keyCode (.getKeyCode e)] (if (== 37 keyCode) (dosync (alter x dec)) (if (== 38 keyCode) (dosync (alter y dec)) (if (== 39 keyCode) (dosync (alter x inc)) (if (== 40 keyCode) (dosync (alter y inc)) (println keyCode))))))) (keyReleased [e]) (keyTyped [e]))) (doto panel (.setFocusable true) (.addKeyListener panel)) (def frame (JFrame. "Test")) (doto frame (.add panel) (.pack) (.setDefaultCloseOperation JFrame/EXIT_ON_CLOSE) (.setVisible true)) (defn drawRectangle [p] (doto (.getGraphics p) (.setColor (java.awt.Color/WHITE)) (.fillRect 0 0 100 100) (.setColor (java.awt.Color/BLUE)) (.fillRect (* 10 (deref x)) (* 10 (deref y)) 10 10))) (loop [] (drawRectangle panel) (Thread/sleep 10) (recur)) Despite being an experienced C++ programmer I found it very challenging to write even a simple application in a language that uses a radically different style than what I'm used to. On top of that, this code probably sucks. I suspect the globalness of the various values is a bad thing. It's also not clear to me if it's appropriate to use references here for the x and y values. Any hints for improving this code are welcome.

    Read the article

  • Parsing data with Clojure, interval problem.

    - by Andrea Di Persio
    Hello! I'm writing a little parser in clojure for learning purpose. basically is a TSV file parser that need to be put in a database, but I added a complication. The complication itself is that in the same file there are more intervals. The file look like this: ###andreadipersio 2010-03-19 16:10:00### USER COMM PID PPID %CPU %MEM TIME root launchd 1 0 0.0 0.0 2:46.97 root DirectoryService 11 1 0.0 0.2 0:34.59 root notifyd 12 1 0.0 0.0 0:20.83 root diskarbitrationd 13 1 0.0 0.0 0:02.84` .... ###andreadipersio 2010-03-19 16:20:00### USER COMM PID PPID %CPU %MEM TIME root launchd 1 0 0.0 0.0 2:46.97 root DirectoryService 11 1 0.0 0.2 0:34.59 root notifyd 12 1 0.0 0.0 0:20.83 root diskarbitrationd 13 1 0.0 0.0 0:02.84 I ended up with this code: (defn is-header? "Return true if a line is header" [line] (> (count (re-find #"^\#{3}" line)) 0)) (defn extract-fields "Return regex matches" [line pattern] (rest (re-find pattern line))) (defn process-lines [lines] (map process-line lines)) (defn process-line [line] (if (is-header? line) (extract-fields line header-pattern)) (extract-fields line data-pattern)) My idea is that in 'process-line' interval need to be merged with data so I have something like this: ('andreadipersio', '2010-03-19', '16:10:00', 'root', 'launchd', 1, 0, 0.0, 0.0, '2:46.97') for every row till the next interval, but I can't figure how to make this happen. I tried with something like this: (def process-line [line] (if is-header? line) (def header-data (extract-fields line header-pattern))) (cons header-data (extract-fields line data-pattern))) But this doesn't work as excepted. Any hints? Thanks!

    Read the article

  • Project Euler #14 and memoization in Clojure

    - by dbyrne
    As a neophyte clojurian, it was recommended to me that I go through the Project Euler problems as a way to learn the language. Its definitely a great way to improve your skills and gain confidence. I just finished up my answer to problem #14. It works fine, but to get it running efficiently I had to implement some memoization. I couldn't use the prepackaged memoize function because of the way my code was structured, and I think it was a good experience to roll my own anyways. My question is if there is a good way to encapsulate my cache within the function itself, or if I have to define an external cache like I have done. Also, any tips to make my code more idiomatic would be appreciated. (use 'clojure.test) (def mem (atom {})) (with-test (defn chain-length ([x] (chain-length x x 0)) ([start-val x c] (if-let [e (last(find @mem x))] (let [ret (+ c e)] (swap! mem assoc start-val ret) ret) (if (<= x 1) (let [ret (+ c 1)] (swap! mem assoc start-val ret) ret) (if (even? x) (recur start-val (/ x 2) (+ c 1)) (recur start-val (+ 1 (* x 3)) (+ c 1))))))) (is (= 10 (chain-length 13)))) (with-test (defn longest-chain ([] (longest-chain 2 0 0)) ([c max start-num] (if (>= c 1000000) start-num (let [l (chain-length c)] (if (> l max) (recur (+ 1 c) l c) (recur (+ 1 c) max start-num)))))) (is (= 837799 (longest-chain))))

    Read the article

  • Fastest reliable way for Clojure (Java) and Ruby apps to communicate

    - by jkndrkn
    Hi There, We have cloud-hosted (RackSpace cloud) Ruby and Java apps that will interact as follows: Ruby app sends a request to Java app. Request consists of map structure containing strings, integers, other maps, and lists (analogous to JSON). Java app analyzes data and sends reply to Ruby App. We are interested in evaluating both messaging formats (JSON, Buffer Protocols, Thrift, etc.) as well as message transmission channels/techniques (sockets, message queues, RPC, REST, SOAP, etc.) Our criteria: Short round-trip time. Low round-trip-time standard deviation. (We understand that garbage collection pauses and network usage spikes can affect this value). High availability. Scalability (we may want to have multiple instances of Ruby and Java app exchanging point-to-point messages in the future). Ease of debugging and profiling. Good documentation and community support. Bonus points for Clojure support. What combination of message format and transmission method would you recommend? Why? I've gathered here some materials we have already collected for review: Comparison of various java serialization options Comparison of Thrift and Protocol Buffers (old) Comparison of various data interchange formats Comparison of Thrift and Protocol Buffers Fallacies of Protocol Buffers RPC features Discussion of RPC in the context of AMQP (Message-Queueing) Comparison of RPC and message-passing in distributed systems (pdf) Criticism of RPC from perspective of message-passing fan Overview of Avro from Ruby programmer perspective

    Read the article

  • Java style FOR loop in a clojure interpeter ?

    - by Kevin
    I have a basic interpreter in clojure. Now i need to implement for (initialisation; finish-test; loop-update) { statements } inside my interpreter. I will attach my interpreter code I got so far. Any help is appreciated. Interpreter (declare interpret make-env) ;; (def do-trace false) ;; ;; simple utilities (def third ; return third item in a list (fn [a-list] (second (rest a-list)))) (def fourth ; return fourth item in a list (fn [a-list] (third (rest a-list)))) (def run ; make it easy to test the interpreter (fn [e] (println "Processing: " e) (println "=> " (interpret e (make-env))))) ;; for the environment (def make-env (fn [] '())) (def add-var (fn [env var val] (cons (list var val) env))) (def lookup-var (fn [env var] (cond (empty? env) 'error (= (first (first env)) var) (second (first env)) :else (lookup-var (rest env) var)))) ;; -- define numbers (def is-number? (fn [expn] (number? expn))) (def interpret-number (fn [expn env] expn)) ;; -- define symbols (def is-symbol? (fn [expn] (symbol? expn))) (def interpret-symbol (fn [expn env] (lookup-var env expn))) ;; -- define boolean (def is-boolean? (fn [expn] (or (= expn 'true) (= expn 'false)))) (def interpret-boolean (fn [expn env] expn)) ;; -- define functions (def is-function? (fn [expn] (and (list? expn) (= 3 (count expn)) (= 'lambda (first expn))))) (def interpret-function (fn [expn env] expn)) ;; -- define addition (def is-plus? (fn [expn] (and (list? expn) (= 3 (count expn)) (= '+ (first expn))))) (def interpret-plus (fn [expn env] (+ (interpret (second expn) env) (interpret (third expn) env)))) ;; -- define subtraction (def is-minus? (fn [expn] (and (list? expn) (= 3 (count expn)) (= '- (first expn))))) (def interpret-minus (fn [expn env] (- (interpret (second expn) env) (interpret (third expn) env)))) ;; -- define multiplication (def is-times? (fn [expn] (and (list? expn) (= 3 (count expn)) (= '* (first expn))))) (def interpret-times (fn [expn env] (* (interpret (second expn) env) (interpret (third expn) env)))) ;; -- define division (def is-divides? (fn [expn] (and (list? expn) (= 3 (count expn)) (= '/ (first expn))))) (def interpret-divides (fn [expn env] (/ (interpret (second expn) env) (interpret (third expn) env)))) ;; -- define equals test (def is-equals? (fn [expn] (and (list? expn) (= 3 (count expn)) (= '= (first expn))))) (def interpret-equals (fn [expn env] (= (interpret (second expn) env) (interpret (third expn) env)))) ;; -- define greater-than test (def is-greater-than? (fn [expn] (and (list? expn) (= 3 (count expn)) (= '> (first expn))))) (def interpret-greater-than (fn [expn env] (> (interpret (second expn) env) (interpret (third expn) env)))) ;; -- define not (def is-not? (fn [expn] (and (list? expn) (= 2 (count expn)) (= 'not (first expn))))) (def interpret-not (fn [expn env] (not (interpret (second expn) env)))) ;; -- define or (def is-or? (fn [expn] (and (list? expn) (= 3 (count expn)) (= 'or (first expn))))) (def interpret-or (fn [expn env] (or (interpret (second expn) env) (interpret (third expn) env)))) ;; -- define and (def is-and? (fn [expn] (and (list? expn) (= 3 (count expn)) (= 'and (first expn))))) (def interpret-and (fn [expn env] (and (interpret (second expn) env) (interpret (third expn) env)))) ;; -- define with (def is-with? (fn [expn] (and (list? expn) (= 3 (count expn)) (= 'with (first expn))))) (def interpret-with (fn [expn env] (interpret (third expn) (add-var env (first (second expn)) (interpret (second (second expn)) env))))) ;; -- define if (def is-if? (fn [expn] (and (list? expn) (= 4 (count expn)) (= 'if (first expn))))) (def interpret-if (fn [expn env] (cond (interpret (second expn) env) (interpret (third expn) env) :else (interpret (fourth expn) env)))) ;; -- define function-application (def is-function-application? (fn [expn env] (and (list? expn) (= 2 (count expn)) (is-function? (interpret (first expn) env))))) (def interpret-function-application (fn [expn env] (let [function (interpret (first expn) env)] (interpret (third function) (add-var env (first (second function)) (interpret (second expn) env)))))) ;; the interpreter itself (def interpret (fn [expn env] (cond do-trace (println "Interpret is processing: " expn)) (cond ; basic values (is-number? expn) (interpret-number expn env) (is-symbol? expn) (interpret-symbol expn env) (is-boolean? expn) (interpret-boolean expn env) (is-function? expn) (interpret-function expn env) ; built-in functions (is-plus? expn) (interpret-plus expn env) (is-minus? expn) (interpret-minus expn env) (is-times? expn) (interpret-times expn env) (is-divides? expn) (interpret-divides expn env) (is-equals? expn) (interpret-equals expn env) (is-greater-than? expn) (interpret-greater-than expn env) (is-not? expn) (interpret-not expn env) (is-or? expn) (interpret-or expn env) (is-and? expn) (interpret-and expn env) ; special syntax (is-with? expn) (interpret-with expn env) (is-if? expn) (interpret-if expn env) ; functions (is-function-application? expn env) (interpret-function-application expn env) :else 'error)))

    Read the article

  • How can I decrease my C# learning curve? [closed]

    - by MSU
    I have been learning programming, mostly C# and .net stuff. And I have target to become a fulltime .NET developer. But I am feeling that learning Graph is very slow, I have been learning C# programming, doing some coding everyday, but how I can learn very fast and increase my skills rapidly? I know there should be a balance of coding and reading, as without reading I can't code and without coding I can't increase my skills. SO, I am requesting here suggesting from experts on how I bring more pace to my learning curve? I intend to give 4-6 hours daily for this and on weekends 10+ hours.

    Read the article

  • How can i bring pace to my Learning Graph?

    - by MSU
    I have been learning programming, mostly C# and .net stuff. And i have target to become a fulltime .NET developer. But i am feeling that learning Graph is very slow, i have been learning C# programming, doing some codes everyday, but how i can learn very fast and increase my skills rapidly. I know there should be a balace of coding and reading, as without reading i can't code and without coding i can't increase my skills. SO, I am requesting here suggestiong from experts on how i bring more pace to my learning graph, i intend to give 4-6 hours daily for this and on weekends 10+ hours ..

    Read the article

  • How can I lower my C# learning curve? [closed]

    - by MSU
    I have been learning programming, mostly C# and .net stuff. And I have target to become a fulltime .NET developer. But I am feeling that learning Graph is very slow, I have been learning C# programming, doing some coding everyday, but how I can learn very fast and increase my skills rapidly? I know there should be a balance of coding and reading, as without reading I can't code and without coding I can't increase my skills. SO, I am requesting here suggesting from experts on how I bring more pace to my learning curve? I intend to give 4-6 hours daily for this and on weekends 10+ hours.

    Read the article

< Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >