Skip to content

Commit

Permalink
Some corrections in accordance with #14
Browse files Browse the repository at this point in the history
  • Loading branch information
Mercerenies committed Jan 5, 2018
1 parent 115ac48 commit a64e503
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 77 deletions.
62 changes: 31 additions & 31 deletions std/args.lats
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,42 @@ ArgList fillWith := {
self.
}.
ArgList shift := {
if (self size == 0)
then { Nil. }
else {
first := parent self enclosingScope slot '$1.
arglist := parent self.
size := parent self size.
temp := #'first.
index := 2.
'index assign = { $1. }.
parent self map! {
if ((index) > (size))
then { #'first. }
else {
result := arglist enclosingScope slot ((("$") ++ (index)) intern).
index = index + 1.
#'result.
}.
if (self size == 0) then {
Nil.
} else {
first := parent self enclosingScope slot '$1.
arglist := parent self.
size := parent self size.
temp := #'first.
index := 2.
'index assign = { $1. }.
parent self map! {
if ((index) > (size)) then {
#'first.
} else {
result := arglist enclosingScope slot ((("$") ++ (index)) intern).
index = index + 1.
#'result.
}.
#'first.
}.
#'first.
}.
}.
ArgList unshift := {
if (self size == 0)
then { Nil. }
else {
first := parent self enclosingScope slot '$1.
arglist := parent self.
size := parent self size.
temp := Nil.
parent self map! {
temp1 := #'temp.
parent temp := #'$1.
#'temp1.
}.
parent self enclosingScope slot '$1 = #'temp.
if (self size == 0) then {
Nil.
} else {
first := parent self enclosingScope slot '$1.
arglist := parent self.
size := parent self size.
temp := Nil.
parent self map! {
temp1 := #'temp.
parent temp := #'$1.
#'temp1.
}.
parent self enclosingScope slot '$1 = #'temp.
}.
}.
ArgList unshiftOnto := {
self enclosingScope slot (("$" ++ (self size + 1)) intern) = #'$1.
Expand Down
91 changes: 45 additions & 46 deletions std/arithmetic.lats
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,23 @@ Number / := { meta sys numDiv#: self, $1. }.
Number mod := {
curr := self.
arg := $1.
if ({ curr isComplex?. } or { arg isComplex?. })
then {
err TypeError clone tap { self message := "Cannot modulo complex numbers". } throw.
} else {
meta sys numMod#: curr, arg.
}.
if ({ curr isComplex?. } or { arg isComplex?. }) then {
err TypeError clone tap { self message := "Cannot modulo complex numbers". } throw.
} else {
meta sys numMod#: curr, arg.
}.
}.
Number ^ := { meta sys numPow#: self, $1. }.

global - := { 0 - ($1). }.
global / := { 1 / ($1). }.

Number floor := {
if { parent self isComplex?. }
then {
err TypeError clone tap { self message := "Cannot round complex numbers". } throw.
} else {
meta sys numFloor#: parent self.
}.
if { parent self isComplex?. } then {
err TypeError clone tap { self message := "Cannot round complex numbers". } throw.
} else {
meta sys numFloor#: parent self.
}.
}.
Number round := { (self + 0.5) floor. }.
Number ceil := { - (- (self) floor). }.
Expand All @@ -38,43 +36,39 @@ Number ceil := { - (- (self) floor). }.
Number bitAnd := {
curr := self.
arg := $1.
if ({ curr isInteger?. } and { arg isInteger?. })
then {
meta sys numAnd#: curr, arg.
} else {
err TypeError clone tap { self message := "Bitwise operation on non-integer". } throw.
}.
if ({ curr isInteger?. } and { arg isInteger?. }) then {
meta sys numAnd#: curr, arg.
} else {
err TypeError clone tap { self message := "Bitwise operation on non-integer". } throw.
}.
}.
Number bitOr := {
curr := self.
arg := $1.
if ({ curr isInteger?. } and { arg isInteger?. })
then {
meta sys numIor#: curr, arg.
} else {
err TypeError clone tap { self message := "Bitwise operation on non-integer". } throw.
}.
if ({ curr isInteger?. } and { arg isInteger?. }) then {
meta sys numIor#: curr, arg.
} else {
err TypeError clone tap { self message := "Bitwise operation on non-integer". } throw.
}.
}.
Number bitXor := {
curr := self.
arg := $1.
if ({ curr isInteger?. } and { arg isInteger?. })
then {
meta sys numEor#: curr, arg.
} else {
err TypeError clone tap { self message := "Bitwise operation on non-integer". } throw.
}.
if ({ curr isInteger?. } and { arg isInteger?. }) then {
meta sys numEor#: curr, arg.
} else {
err TypeError clone tap { self message := "Bitwise operation on non-integer". } throw.
}.
}.
Number bitNot := { self bitXor -1. }.
Number bitShift := {
curr := self.
arg := $1.
if ({ curr isInteger?. } and { arg isInteger?. })
then {
(curr) * (2 ^ (arg)) floor.
} else {
err TypeError clone tap { self message := "Bitwise operation on non-integer". } throw.
}.
if ({ curr isInteger?. } and { arg isInteger?. }) then {
(curr) * (2 ^ (arg)) floor.
} else {
err TypeError clone tap { self message := "Bitwise operation on non-integer". } throw.
}.
}.

;; Trigonometry
Expand Down Expand Up @@ -141,12 +135,15 @@ String radix := {
convert := {
takes '[n].
cond {
when { (n >= ("0" ord)) and (n <= ("9" ord)). }
do { n - ("0" ord). }.
when { (n >= ("a" ord)) and (n <= ("z" ord)). }
do { n - ("a" ord) + 10. }.
when { (n >= ("A" ord)) and (n <= ("Z" ord)). }
do { n - ("A" ord) + 10. }.
when { (n >= ("0" ord)) and (n <= ("9" ord)). } do {
n - ("0" ord).
}.
when { (n >= ("a" ord)) and (n <= ("z" ord)). } do {
n - ("a" ord) + 10.
}.
when { (n >= ("A" ord)) and (n <= ("Z" ord)). } do {
n - ("A" ord) + 10.
}.
else {
err InputError clone tap {
self message := "Text is not a number".
Expand Down Expand Up @@ -174,10 +171,12 @@ modifiedRadix := {
takes '[str, rad, parm].
result := str radix: rad.
cond {
when (parm == '-)
do { - (result). }.
when ((parm == '+) or (parm == '()))
do { result. }.
when (parm == '-) do {
- (result).
}.
when ((parm == '+) or (parm == '())) do {
result.
}.
else {
err ArgError clone tap {
self message := "Sign does not make sense".
Expand Down

0 comments on commit a64e503

Please sign in to comment.