Skip to content

Commit

Permalink
Wrap comments at 80 chars.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoglan committed Jun 29, 2012
1 parent 121425a commit 3f372b2
Show file tree
Hide file tree
Showing 44 changed files with 863 additions and 922 deletions.
9 changes: 5 additions & 4 deletions lib/heist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ def parse(source)
parser.parse(source)
end

# Returns the result of evaluating the given +Expression+ in the given +Scope+.
# If the first argument is not an +Expression+ it will be returned unaltered.
# Returns the result of evaluating the given +Expression+ in the given
# +Scope+. If the first argument is not an +Expression+ it will be returned
# unaltered.
def evaluate(expression, scope)
return expression.value if Runtime::Value === expression
Runtime::Expression === expression ?
Expand All @@ -58,8 +59,8 @@ def evaluate(expression, scope)
end

# Returns the result of dividing the first argument by the second. If both
# arguments are integers, returns a rational rather than performing
# integer division as Ruby would normally do.
# arguments are integers, returns a rational rather than performing integer
# division as Ruby would normally do.
def divide(op1, op2)
[op1, op2].all? { |value| Integer === value } ?
Rational(op1, op2) :
Expand Down
6 changes: 3 additions & 3 deletions lib/heist/builtin/lib/character.scm
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
; (char string)
; Returns a character from a single-character string. Mostly
; useful for succinct representation of characters in hand-
; written Ruby code.
; Returns a character from a single-character string. Mostly useful for succinct
; representation of characters in hand-written Ruby code.
(define (char string)
(if (and (string? string) (= (string-length string) 1))
(string-ref string 0)
Expand Down Expand Up @@ -72,3 +71,4 @@
(define char-ci>? (char-compare-ci char>?))
(define char-ci<=? (char-compare-ci char<=?))
(define char-ci>=? (char-compare-ci char>=?))

46 changes: 20 additions & 26 deletions lib/heist/builtin/lib/list.scm
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
(iter object 0))

; (append list ...)
; Returns a new list formed by concatenating the arguments.
; The final argument is not copied and the return value of
; (append) shares structure with it.
; Returns a new list formed by concatenating the arguments. The final argument
; is not copied and the return value of (append) shares structure with it.
(define (append first . rest)
(cond ((null? rest) first)
((null? first) (apply append rest))
Expand All @@ -36,17 +35,16 @@
(apply append rest))))))

; (reverse list)
; Returns a newly allocated list consisting of the
; elements of list in reverse order.
; Returns a newly allocated list consisting of the elements of list in reverse
; order.
(define (reverse object)
(if (null? object)
object
(append (reverse (cdr object))
(list (car object)))))

; (list-tail list k)
; Returns the sublist of list obtained by omitting the
; first k elements.
; Returns the sublist of list obtained by omitting the first k elements.
(define (list-tail list k)
(do ((pair list (cdr pair))
(i k (- i 1)))
Expand All @@ -60,13 +58,11 @@
; (memq obj list)
; (memv obj list)
; (member obj list)
; These procedures return the first sublist of list whose
; car is obj, where the sublists of list are the non-empty
; lists returned by (list-tail list k) for k less than the
; length of list. If obj does not occur in list, then #f
; (not the empty list) is returned. Memq uses eq? to compare
; obj with the elements of list, while memv uses eqv? and
; member uses equal?.
; These procedures return the first sublist of list whose car is obj, where the
; sublists of list are the non-empty lists returned by (list-tail list k) for k
; less than the length of list. If obj does not occur in list, then #f (not the
; empty list) is returned. Memq uses eq? to compare obj with the elements of
; list, while memv uses eqv? and member uses equal?.

(define (list-transform-search transform)
(lambda (predicate)
Expand All @@ -86,22 +82,20 @@
; (assq obj alist)
; (assv obj alist)
; (assoc obj alist)
; Alist (for "association list") must be a list of pairs.
; These procedures find the first pair in alist whose car
; field is obj, and returns that pair. If no pair in alist
; has obj as its car, then #f (not the empty list) is
; returned. Assq uses eq? to compare obj with the car fields
; of the pairs in alist, while assv uses eqv? and assoc
; uses equal?.
; Alist (for "association list") must be a list of pairs. These procedures find
; the first pair in alist whose car field is obj, and returns that pair. If no
; pair in alist has obj as its car, then #f (not the empty list) is returned.
; Assq uses eq? to compare obj with the car fields of the pairs in alist, while
; assv uses eqv? and assoc uses equal?.

(define assoc-list-search (list-transform-search car))
(define assq (assoc-list-search eq?))
(define assv (assoc-list-search eqv?))
(define assoc (assoc-list-search equal?))

; (map proc list1 list2 ...)
; Returns a new list formed by applying proc to each member
; (or set of members) of the given list(s).
; Returns a new list formed by applying proc to each member (or set of members)
; of the given list(s).
(define (map proc list1 . list2)
(if (null? list1)
list1
Expand All @@ -115,9 +109,8 @@
(apply map (cons proc rest)))))))

; (for-each proc list1 list2 ...)
; Calls proc once for each member of list1, passing each
; member (or set of members if more than one list given)
; as arguments to proc.
; Calls proc once for each member of list1, passing each member (or set of
; members if more than one list given) as arguments to proc.
(define (for-each proc list1 . list2)
(do ((pair list1 (cdr pair))
(others list2 (map cdr others)))
Expand Down Expand Up @@ -147,3 +140,4 @@
((<= end 0) '())
(else (cons (car list)
(sublist (cdr list) 0 (- end 1))))))

1 change: 1 addition & 0 deletions lib/heist/builtin/lib/logic.scm
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
; Returns true iff x is a boolean value
(define (boolean? x)
(or (eqv? x #t) (eqv? x #f)))

26 changes: 12 additions & 14 deletions lib/heist/builtin/lib/numeric.scm
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
(define number? complex?)

; (exact? x)
; Returns true iff the given number is exact i.e. an integer, a
; rational, or a complex made of integers or rationals
; Returns true iff the given number is exact i.e. an integer, a rational, or a
; complex made of integers or rationals
(define (exact? x)
(or (rational? x)
(and (not (zero? (imag-part x)))
Expand Down Expand Up @@ -81,8 +81,8 @@
; (remainder n1 n2)))

; (quotient x y)
; Returns the quotient of two numbers, i.e. performs n1/n2
; and rounds toward zero.
; Returns the quotient of two numbers, i.e. performs n1/n2 and rounds toward
; zero.
(define (quotient x y)
(let ((result (/ x y)))
((if (positive? result)
Expand All @@ -91,8 +91,7 @@
result)))

; (remainder x y)
; Returns the remainder after dividing the first operand
; by the second
; Returns the remainder after dividing the first operand by the second
(define (remainder x y)
(- (round x)
(* (round y)
Expand Down Expand Up @@ -128,10 +127,9 @@
(define ceiling ceil)

; (rationalize x tolerance)
; Returns the simplest rational number that differs from x by
; no more than tolerance. Here 'simplest' means the smallest
; possible denominator is found first, and with that set the
; smallest corresponding numerator is chosen.
; Returns the simplest rational number that differs from x by no more than
; tolerance. Here 'simplest' means the smallest possible denominator is found
; first, and with that set the smallest corresponding numerator is chosen.
(define (rationalize x tolerance)
(cond ((rational? x)
x)
Expand All @@ -152,8 +150,7 @@
i)))))))))

; (make-polar magnitude angle)
; Returns a new complex number with the given
; magnitude and angle
; Returns a new complex number with the given magnitude and angle
(define (make-polar magnitude angle)
(let ((re (* magnitude (cos angle)))
(im (* magnitude (sin angle))))
Expand All @@ -167,8 +164,8 @@
(sqrt (+ (* re re) (* im im)))))

; (angle z)
; Returns the angle a complex number makes with the
; real axis when plotted in the complex plane
; Returns the angle a complex number makes with the real axis when plotted in
; the complex plane
(define (angle z)
(let ((re (real-part z))
(im (imag-part z)))
Expand All @@ -182,3 +179,4 @@
acc
(iter (- y 1) (* y acc))))
(iter x 1))

27 changes: 13 additions & 14 deletions lib/heist/builtin/lib/string.scm
Original file line number Diff line number Diff line change
Expand Up @@ -39,44 +39,42 @@
(= (string-compare string1 string2 char<? char>?) 1))

; (string<=? string1 string2)
; Returns true iff string1 is lexicographically less than or equal
; to string2
; Returns true iff string1 is lexicographically less than or equal to string2
(define (string<=? string1 string2)
(not (string>? string1 string2)))

; (string>=? string1 string2)
; Returns true iff string1 is lexicographically greater than or equal
; to string2
; Returns true iff string1 is lexicographically greater than or equal to string2
(define (string>=? string1 string2)
(not (string<? string1 string2)))

; (string-ci<? string1 string2)
; Returns true iff string1 is lexicographically less than string2,
; ignoring differences in case
; Returns true iff string1 is lexicographically less than string2, ignoring
; differences in case
(define (string-ci<? string1 string2)
(= (string-compare string1 string2 char-ci<? char-ci>?) -1))

; (string-ci>? string1 string2)
; Returns true iff string1 is lexicographically greater than string2,
; ignoring differences in case
; Returns true iff string1 is lexicographically greater than string2, ignoring
; differences in case
(define (string-ci>? string1 string2)
(= (string-compare string1 string2 char-ci<? char-ci>?) 1))

; (string-ci<=? string1 string2)
; Returns true iff string1 is lexicographically less than or equal
; to string2, ignoring differences in case
; Returns true iff string1 is lexicographically less than or equal to string2,
; ignoring differences in case
(define (string-ci<=? string1 string2)
(not (string-ci>? string1 string2)))

; (string-ci>=? string1 string2)
; Returns true iff string1 is lexicographically greater than or equal
; to string2, ignoring differences in case
; Returns true iff string1 is lexicographically greater than or equal to
; string2, ignoring differences in case
(define (string-ci>=? string1 string2)
(not (string-ci<? string1 string2)))

; (substring string start end)
; Returns a string composed of the characters from start (inclusive)
; to end (exclusive) in string
; Returns a string composed of the characters from start (inclusive) to end
; (exclusive) in string
(define (substring string start end)
(list->string (sublist (string->list string) start end)))

Expand Down Expand Up @@ -115,3 +113,4 @@
; Returns a new string formed by concatenating the arguments
(define (string-append . strings)
(list->string (apply append (map string->list strings))))

6 changes: 3 additions & 3 deletions lib/heist/builtin/lib/util.scm
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
; Any built-in functions that we can implement directly
; in Scheme should go here. If at all possible, write
; builtins in Scheme rather than Ruby.
; Any built-in functions that we can implement directly in Scheme should go
; here. If at all possible, write builtins in Scheme rather than Ruby.

(define quit exit)

Expand All @@ -16,3 +15,4 @@
; (call/cc)
; Alias for (call-with-current-continuation)
(define call/cc call-with-current-continuation)

1 change: 1 addition & 0 deletions lib/heist/builtin/lib/vector.scm
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@
(do ((i (vector-length vector) (- i 1)))
((zero? i) vector)
(vector-set! vector (- i 1) fill)))

Loading

0 comments on commit 3f372b2

Please sign in to comment.