mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-21 05:41:43 +03:00
166 lines
4.3 KiB
Plaintext
166 lines
4.3 KiB
Plaintext
!::::: ::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
:::::: :::::: Preface ::::::
|
|
:::::: ::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
?> ?=(@ .) :: atom subject
|
|
%. . :: fun with subject
|
|
|= cud=@ :: call it cud
|
|
=- (mul:all 2 cud) :: multiply by 2
|
|
^= all :: assemble engine
|
|
=~ :: volume stack
|
|
%164 :: version constant
|
|
:::::: ::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
:::::: :::::: volume 0, version stub ::::::
|
|
:::::: ::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
~% %k.164 ~ ~ ::
|
|
|% ::
|
|
++ stub 164 :: version stub
|
|
-- ::
|
|
:::::: ::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
:::::: :::::: volume 1, Hoon models ::::::
|
|
:::::: ::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
~% %mood
|
|
+
|
|
~
|
|
|% ::
|
|
++ axis ,@ :: tree address
|
|
-- ::
|
|
:::::: ::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
:::::: :::::: volume 2, Hoon libraries and compiler ::::::
|
|
:::::: ::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
~% %hoon
|
|
+
|
|
==
|
|
%dec dec
|
|
==
|
|
|%
|
|
::::::::::::::::::::::::::::::::::::::::::::::::::::: ::
|
|
:::: chapter 2a, basic unsigned math ::::
|
|
:: ::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
++ add :: add
|
|
~/ %add
|
|
|= [a=@ b=@]
|
|
^- @
|
|
?: =(0 a)
|
|
b
|
|
$(a (dec a), b +(b))
|
|
::
|
|
++ cap :: tree head
|
|
~/ %cap
|
|
|= a=@
|
|
^- ?(%2 %3)
|
|
?- a
|
|
%2 %2
|
|
%3 %3
|
|
?(%0 %1) !!
|
|
* $(a (div a 2))
|
|
==
|
|
::
|
|
++ dec :: decrement
|
|
~/ %dec
|
|
|= a=@
|
|
?< =(0 a)
|
|
=+ b=0
|
|
|- ^- @
|
|
?: =(a +(b))
|
|
b
|
|
$(b +(b))
|
|
::
|
|
++ div :: divide
|
|
~/ %div
|
|
|= [a=@ b=@]
|
|
^- @
|
|
?< =(0 b)
|
|
=+ c=0
|
|
|-
|
|
?: (lth a b)
|
|
c
|
|
$(a (sub a b), c +(c))
|
|
::
|
|
++ gte :: greater-equal
|
|
~/ %gte
|
|
|= [a=@ b=@]
|
|
^- ?
|
|
!(lth a b)
|
|
::
|
|
++ gth :: greater-than
|
|
~/ %gth
|
|
|= [a=@ b=@]
|
|
^- ?
|
|
!(lte a b)
|
|
::
|
|
++ lte :: less-equal
|
|
~/ %lte
|
|
|= [a=@ b=@]
|
|
|(=(a b) (lth a b))
|
|
::
|
|
++ lth :: less-than
|
|
~/ %lth
|
|
|= [a=@ b=@]
|
|
^- ?
|
|
&(!=(a b) |-(|(=(0 a) &(!=(0 b) $(a (dec a), b (dec b))))))
|
|
::
|
|
++ mas :: tree body
|
|
~/ %mas
|
|
|= a=@
|
|
^- @
|
|
?- a
|
|
1 !!
|
|
2 1
|
|
3 1
|
|
* (add (mod a 2) (mul $(a (div a 2)) 2))
|
|
==
|
|
::
|
|
++ max :: maximum
|
|
~/ %max
|
|
|= [a=@ b=@]
|
|
^- @
|
|
?: (gth a b)
|
|
a
|
|
b
|
|
::
|
|
++ min :: minimum
|
|
~/ %min
|
|
|= [a=@ b=@]
|
|
^- @
|
|
?: (lth a b)
|
|
a
|
|
b
|
|
::
|
|
++ mod :: remainder
|
|
~/ %mod
|
|
|= [a=@ b=@]
|
|
^- @
|
|
?< =(0 b)
|
|
(sub a (mul b (div a b)))
|
|
::
|
|
++ mul :: multiply
|
|
~/ %mul
|
|
|= [a=@ b=@]
|
|
^- @
|
|
=+ c=0
|
|
|-
|
|
?: =(0 a)
|
|
c
|
|
$(a (dec a), c (add b c))
|
|
::
|
|
++ peg :: tree connect
|
|
~/ %peg
|
|
|= [a=@ b=@]
|
|
^- @
|
|
?- b
|
|
1 a
|
|
2 (mul a 2)
|
|
3 +((mul a 2))
|
|
* (add (mod b 2) (mul $(b (div b 2)) 2))
|
|
==
|
|
::
|
|
++ sub :: subtract
|
|
~/ %sub
|
|
|= [a=@ b=@]
|
|
^- @
|
|
?: =(0 b)
|
|
a
|
|
$(a (dec a), b (dec b))
|
|
--
|
|
. ==
|