- Clojure, the core data structures aren't mutable
Clojure has two types of expressions atoms and collections
Atoms represent Primitive Types in other languages, like:
Numbers, Strings, Boolean, Nil, Symbols, Keywords
| #Frg Jmp | |
| def solution(x, y, d) | |
| # write your code in Ruby 1.9.3 | |
| diff = (y - x) | |
| return 0 if diff.zero? | |
| i = (diff.to_f/d).ceil | |
| return i | |
| end |
| ; as clojure is built on top of Java, many of its types are old java types | |
| (class 3) | |
| => java.lang.Long |
| ; Comments start with semicolons. | |
| ; Clojure is written in "forms", which are just | |
| ; lists of things inside parentheses, separated by whitespace. | |
| ; | |
| ; The clojure reader assumes that the first thing is a | |
| ; function or macro to call, and the rest are arguments. | |
| ; | |
| ; Here's a function that sets the current namespace: | |
| (ns test) |
| ; Comments start with semicolons. | |
| ; Clojure is written in "forms", which are just | |
| ; lists of things inside parentheses, separated by whitespace. | |
| ; | |
| ; The clojure reader assumes that the first thing is a | |
| ; function or macro to call, and the rest are arguments. | |
| ; | |
| ; Here's a function that sets the current namespace: | |
| (ns test) |
| ;; eg: symbols in clojure, points to a verb or other values | |
| ;; when clojure evaluates a symbol it looks up that symbols meaning | |
| inc | |
| ;; refer to symbols without evaluating its meaning | |
| ;; ' escapes a expression. Quote anything and get it back exactly | |
| ;; the same | |
| 'inc |
| ###In order to use ruby-debug with ruby-1.9.3 you need to download the following from http://rubyforge.org/frs/?group_id=8883 ### | |
| linecache19-0.5.13.gem | |
| ruby_core_source-0.1.5.gem | |
| ruby-debug19-0.11.6.gem | |
| ruby-debug-base19-0.11.26.gem | |
| ###then from the terminal run,### | |
| gem install ruby_core_source-0.1.5.gem -- --with-ruby-include=$rvm_path/src/ruby-1.9.3-p0 |
| # in Gemfile | |
| gem "fastercsv", :platforms => [:mri_18, :ruby_18] | |
| # in app/config/environment.rb | |
| require "csv" | |
| unless !CSV.const_defined? :Reader | |
| require "fastercsv" |
| l = "i am what i am" | |
| # to integer | |
| l.unpack('U*') # => [105, 32, 97, 109, 32, 119, 104, 97, 116, 32, 105, 32, 97, 109] | |
| # to hex | |
| l.unpack('H*') # => ["6920616d2077686174206920616d"] | |
| # if you want the hex in array form then | |
| l.unpack('U*').map{|i| i.to_s(16)} # => ["69", "20", "61", "6d", "20", "77", "68", "61", "74", "20", "69", "20", "61", "6d"] |