Permalink
Browse files

initial checkin

  • Loading branch information...
0 parents commit fe5cab36596e99a302922b15fafd76a96d529582 Michael Bacarella committed Sep 11, 2011
Showing with 103 additions and 0 deletions.
  1. +100 −0 1_strings.clj
  2. +1 −0 CREDITS
  3. +1 −0 README
  4. +1 −0 core.clj
@@ -0,0 +1,100 @@
+;; 1. Strings
+;; Introduction
+
+; ---------------------------
+(def string "\\n") ; two characters, \ and an n
+(def string "Jon 'Maddog' Orwant") ; literal single quotes
+; ---------------------------
+(def string "\n") ; "newline" character
+(def string "Jon \"Maddog\" Orwant") ; literal double quotes
+
+(def a "
+ This is a multiline here document
+ terminated by one double quote.
+ ")
+
+;; Accessing Substrings
+(def value (.substring string offset (+ offset count)))
+(def value (.substring string offset (.length string)))
+
+; or
+(def value (sub_end string offset))
+; using
+(defn sub_end [string offset]
+ (.substring string offset (.length string)))
+
+
+; -----------------------------
+; get a 5-byte string, skip 3, then grab 2 8-byte strings, then the rest
+
+; split at 'sz' byte boundaries
+(defn split-every-n-chars [sz string]
+ (if (= string "")
+ ()
+ (try
+ (let [beg (.substring string 0 sz)
+ rest (sub_end string sz)]
+ (cons beg (split-every-n-chars sz rest)))
+ (catch Exception _e string))))
+
+(def fivers (split-every-n-chars 5 string)
+
+; chop string into individual characters
+(def chars (map (fn [x] (.charAt x 0)) (split-every-n-chars 1 string)))
+
+; -----------------------------
+(def string "This is what you have")
+; Indexes are left to right. There is no possibility to index
+; directly from right to left
+; "T"
+(def first (.substring string 0 1))
+; "is"
+(def start (.substring string 5 7))
+; "you have"
+(def rest (.substring string 13 (.length string)))
+; "e" *)
+(def last (let [len (.length string)]
+ (.substring string (- len 1) len)))
+; "have"
+(def theend (let [len (.length string)]
+ (.substring string (- len 4) len)))
+; "you"
+(def piece (let [len (.length string)]
+ (.substring string (- len 8) (- len 5))))
+
+; -----------------------------
+(def string "This is what you have")
+(format "%s" "string")
+
+; Change "is" to "wasn't"
+(def string (str
+ (.substring string 0 4)
+ " wasn't "
+ (sub_end string 8)))
+; This wasn't what you have
+
+; This wasn't wonderous
+(def string
+ (str (.substring string 0 (- (.length string) 12)) "ondrous"))
+
+; delete first character
+(def string (.substring string 1 (.length string)))
+; his wasn't wondrous
+
+; delete last 10 characters
+(def string (.substring string 0 (- (.length string) 10)))
+; his wasn'
+; -----------------------------
+
+;; Establishing a Default Value
+
+; -----------------------------
+; use b if b is true, else c
+(def a (or b c))
+
+(when-not x (def x y))
+
+; use b if b is defined, otherwise c
+(def a (if (find (ns-interns *ns*) 'b) b c))
+; -----------------------------
+(def foo (or bar "DEFAULT VALUE"))
@@ -0,0 +1 @@
+Michael Bacarella <mbac@panix.com>
1 README
@@ -0,0 +1 @@
+Project to complete PLEAC Clojure.
@@ -0,0 +1 @@
+(ns pleac-clojure.core)

0 comments on commit fe5cab3

Please sign in to comment.