Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

node.js is the new java

Name: Anonymous 2012-09-09 8:35

it greatly improves on it's predecessors
familiar syntax
it's designed to be practical, to the chagrin of CS purists
next-generation of applications being built (hadoop, palantir, runsecape :  asana, meteor)

Name: Anonymous 2012-09-10 6:28

>>21
Some example code in it...

m:with @Xs X \= $X $@Xs

_ X -> y
_? X -> ptrEq _ X

abort = cl (abort)
tag X = cl (`get-type` X)

bound? X = cl (boundp X)

prn X = cl (prn X)

pp X = say X p:ø = X


m:i   X \= cl (let ((&X @$X)) (declare (fixnum &X)) &X)
m:f4  X \= cl (let ((&X @$X)) (declare (`single-float` &X)) &X)
m:i8  X \= cl (let ((&X @$X)) (declare (`double-float` &X)) &X)
m:is  X \= cl (let ((&X @$X)) (declare ((`simple-array` fixnum) &X)) &X)
m:f4s X \= cl (let ((&X @$X)) (declare ((`simple-array` `single-float`) &X)) &X)
m:f8s X \= cl (let ((&X @$X)) (declare ((`simple-array` `double-float`) &X)) &X)

m:unsafe @Body \= cl (locally (declare (optimize (safety 0) (speed 3))) @$Body)

// Usage: alias vlfn veryLongFunctionName
m:alias A B \= (m:$A @Xs = «$$B $@Xs»)

dasm X = cl (disassemble X) = ø

immediate? X = cl (and (imm? X) (not (`fn-sym?` X)))
m:dup N @X = {lt X,len 2 && immediate? X,0 = «vec $N init:$X,0»; «vec $N | map <&A=@$X>»}

// not beginning with, like ^ in regexps (use with pattern matcher)
m:nb X = \<&L = ne (lhd &L) $X>

// usage: foo X:of,«A B C» = say "X is one of the first three letters"
m:of Xs \= <&X = fnd &X $Xs>
sconc a b = conc a b | sym

filter f Xs = fold <A B = {f B = [@A It]; A}> [[]@Xs]
flat [@Xs] = mapc flat Xs;  X=[X]
includes P [X:_:@!P @_]=X; P [_@Xs] = includes P Xs

rmap f [@Xs] = map (rmap f ?) Xs | f
    ;f X = f X

digits X = map num X,prn,str

//insert `sep` between elements of a list `l`
//Usage: infix "+" {a b c}
//Example: map ?,hex "LISP" | infix " " | fold sconc
//TODO: add flag to create (`+` A (`+` B C)) like lists
infix Sep L = fold [@? Sep ??] [(take 1 L) @L,ltl]
join S Xs = infix S Xs | fold conc

cut P S Xs = drop P Xs | take S

// mappend from CL
// Example: maps I=" " ?,hex str,"LISP"
mapc f Xs I:{ø} = map f !Xs = {I = infix I !Xs} = fold conc Xs

subst Src Dst L = map <!Src=Dst; X=X> L

// takeInit odd? [1 5 1 2 3 1 1 2 3] --> (1 5 1)
takeInit P [@Xs @(nb P)] = Xs // Take initial elements for which `p` is true

trim Xs S:{" "} I:{ø} L:{√} R:{√}
 = Xs:Xs,str
   X:{L &&  (pos (ne ? S) Xs) = It; 0}
   Y:{R && ~(pos (ne ? S) Xs) = It; 0}
 = {I = conc (take X Xs) (take Y Xs); drop Y (drop X Xs)} | sym

// break list into piles of `n` items
grp N [@Xs] = [(take N Xs) @(drop N Xs | grp N)]

// partition by `f`
part f Xs = R:ø = map <X=[@!R.(f X) X]> Xs = map ?,1 R

// Example1: unfold <1=ø; X=[X-1 1]> 7
// Example2: qsort Xs = Xs |
//             unfold <[X]    = X
//                    ;[X@Xs] = [(keep (lt ? X) Xs) [X] (keep (gt ? X) Xs)]>
unfold f O = f O | <ø=[O]; Xs = mapc (unfold f ?) Xs>

// counts the number of ones in the bit representation of an integer
// use it to calculate size of bitmasks
bitCount X = cl (logcount X)

// bit-length of an integer:  2^(log 2 ? | ceil)
bitLen X = cl (`integer-length` X)

// inverts `bits` bits in `value` (bitwise not)
inv Bits Value = cl (logxor (ash 1 Bits)-1 Value)

exp X = cl (exp X)
log Base X = cl (log X Base)
sin X = cl (sin X)
cos X = cl (cos X)
tan X = cl (tan X)
asin X = cl (asin X)
acos X = cl (acos X)
atan X = cl (atan X)

sum S = fold `+` [0@S]
prod S = fold `*` [1@S]
avg Xs = Xs,sum/Xs,len
dot Xs Ys = cl (`dot-lists` Xs Ys)
abs X = {num? X = cl abs X; cl (`dot-lists` X X) | sqrt}
norm V = V/V,abs
transpose V = N:0 = [V,lhd,len++(map <X = I:N = !N+1 = X,I> V)]


pick Xs:y? = cl (ind Xs (random (len Xs)))
randRng S E = (abs E+1-S),rand+S
//shuffle Xs = sort Xs by:<X=1.0,rand>
//shuffle Xs:y? = I:Xs,len,rand = [Xs,I @(shuffle ~@Xs,I)]

// convert list to set (an ordered list that does not have duplicated elements)
uniq L = L,sort,<[@A X X @B]=[@A @[X @B],r]; E=E>

// set operations
union A B = A,<[X@Xs] = {fnd X B =    Xs,r ; [X@Xs,r]}; _=B>
isect A B = A,<[X@Xs] = {fnd X B = [X@Xs,r];    Xs,r}>
diff A B = union (skip (fnd ? B) A) (skip (fnd ? A) B)
ss [X@Xs] = R:{ss Xs; [ø]} [@R @(map [X @?] R)]

m:ldb Pos Size Value \= <P S V = (cl ldb (byte S P) V)> $Pos $Size $Value

maximize p [M@Xs]
 = S:M,p = fe <X = NS:X,p = {NS > S = (M=X) = (S=NS)}> Xs = M
 
minimize p [M@Xs]
 = S:M,p = fe <X = NS:X,p = {NS < S = (M=X) = (S=NS)}> Xs = M

m:while Test @Expr \= fc <= {$Test = $Expr = r}>
m:until Test @Expr \= while (n? $Test) $@Expr
m:loop Expr \= fc <:&r = $Expr = &r>

// Usage: times I:10 say i
m:times Head @Expr = C:Head,<[":" C N]=C; _=\&C>
                     N:Head,<[":" C N]=N; X=X  >
                  \= &E:$N = 0,<:&r (&E) $C = $Expr = &r $C+1>

// for (I:0; I<6; !I+1) say I
m:for «$@V; $@C; $@I» @Body = \(= $@V = cl (while @$C @$Body $@(map \@$? I)))
     ;[":" $X $Xs] @Body \= fe <$X=$@Body> $Xs

// usage: gen X^2 for X:1..10 if X,odd?
//        gen [X Y Z] for X:1..21 Y:X..21 Z:Y..21 if X^2 + Y^2 == Z^2
//m:gen @E \for @F \if @C
//  \= &Xs:n try &Xs $@(map <[O A B]=[O A \(amb $B)]> F)
//       {$@C = [@!&Xs $@E]}
//       bt


// these will generate list of ascending/descending numbers
// FIXME: merge these into `..`
asc Start = seq Start (asc Start+1)
dsc Start = seq Start (dsc Start-1)

// repeat sequence
rep [@Xs] = N:Xs,len 0,<I = seq Xs,(I%N) (r I+1)>


seqMap f [X@Xs] = seq X,f (seqMap f Xs)
seqConc [A@As] Bs = seq A (seqConc As Bs)
       ;  _    Bs = Bs
seqAdd [A@As] [B@Bs] = seq A+B (seqAdd As Bs)


words S = subst "\n" " " S,str | split " " | skip n? | map sym
lines S = split "\n" S,str
flines Name = fget Name | split "\n",int | map utf8dec

// maps values in sorted list
bmap f Xs = map <[K V]=[K V,f]> Xs

// count number of P occurencies in Xs
cnt P Xs = C:0 = for X:Xs {eq X P = !C+1} = C

zip A B = map [? ??] A B
enum Xs = I:~1 = map [!I+1 ?] Xs

m:pop L = \(&R:(lhd $L) = ltl !$L = &R)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List