mirror of
https://github.com/janet-lang/janet
synced 2026-09-09 19:09:11 +00:00
Change convention for naming modules and functions.
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
# Example of dst bytecode assembly
|
||||
|
||||
# Fibonacci sequence, implemented with naive recursion.
|
||||
(def fibasm (asm '{
|
||||
(def fibasm (asm/asm '{
|
||||
arity 1
|
||||
bytecode [
|
||||
(ldi 1 0x2) # $1 = 2
|
||||
(lt 1 0 1) # $1 = $0 < $1
|
||||
(jmpif 1 :done) # if ($1) goto :done
|
||||
(jmpif 1 :done) # if ($1) goto :done
|
||||
(lds 1) # $1 = self
|
||||
(addim 0 0 -0x1) # $0 = $0 - 1
|
||||
(push 0) # push($0), push argument for next function call
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
(defn iter2array [itr]
|
||||
(def {:more more :next next} (iter itr))
|
||||
(def a @[])
|
||||
(while (more) (array-push a (next)))
|
||||
(while (more) (array.push a (next)))
|
||||
a)
|
||||
|
||||
(defn map [f itr]
|
||||
|
||||
+1
-12
@@ -18,7 +18,7 @@ body once, and then memoizes the result."
|
||||
$state
|
||||
(tuple 'do
|
||||
(tuple ':= $loaded true)
|
||||
(tuple ':= $state (tuple-prepend forms 'do)))))))
|
||||
(tuple ':= $state (tuple.prepend forms 'do)))))))
|
||||
|
||||
# Use tuples instead of structs to save memory
|
||||
(def HEAD :private 0)
|
||||
@@ -129,14 +129,3 @@ body once, and then memoizes the result."
|
||||
(when-let [n (node)]
|
||||
(:= node (get n 1))
|
||||
(get n 0)))})
|
||||
|
||||
# Now we can use the non-functional filter from boot.dst
|
||||
# to write a filter version that returns a lazy sequence
|
||||
# Be careful when creating lazy sequences from mutable
|
||||
# data structures as their values are references to this
|
||||
# data structures. Same is true for iterators
|
||||
|
||||
(defn filter2 [pred coll] (iter2lazy (filter pred coll)))
|
||||
|
||||
# be careful with the filter function. First element in (filter pos? arr) is nil
|
||||
# last element is false
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
# of the triangle to the leaves of the triangle.
|
||||
|
||||
(defn myfold [xs ys]
|
||||
(def xs1 (tuple-prepend xs 0))
|
||||
(def xs2 (tuple-append xs 0))
|
||||
(def m1 (map + xs1 ys))
|
||||
(def m2 (map + xs2 ys))
|
||||
(map max m1 m2))
|
||||
(let [xs1 (tuple.prepend xs 0)
|
||||
xs2 (tuple.append xs 0)
|
||||
m1 (map + xs1 ys)
|
||||
m2 (map + xs2 ys)]
|
||||
(map max m1 m2)))
|
||||
|
||||
(defn maxpath [t]
|
||||
(extreme > (reduce myfold () t)))
|
||||
|
||||
+1
-1
@@ -10,5 +10,5 @@
|
||||
(for [j 0 len]
|
||||
(def trial (get list j))
|
||||
(if (zero? (% i trial)) (:= isprime? false)))
|
||||
(if isprime? (array-push list i)))
|
||||
(if isprime? (array.push list i)))
|
||||
list)
|
||||
|
||||
Reference in New Issue
Block a user