Skip to content

Commit

Permalink
Add 12 SRFI-1 procedures and more thorough check of list mutability
Browse files Browse the repository at this point in the history
  • Loading branch information
feeley committed Jan 1, 2024
1 parent 5f517cd commit 9aadef4
Show file tree
Hide file tree
Showing 26 changed files with 1,068 additions and 260 deletions.
16 changes: 15 additions & 1 deletion doc/gambit.txi
Original file line number Diff line number Diff line change
Expand Up @@ -5471,9 +5471,14 @@ The procedures in this section are not yet documented.
@end deffn

@deffn procedure filter @var{pred} @var{list}
@deffnx procedure filter! @var{pred} @var{list}
@deffnx procedure remove @var{pred} @var{list}
@deffnx procedure remove! @var{pred} @var{list}
@deffnx procedure partition @var{pred} @var{list}
@deffnx procedure remq @var{elem} @var{list}
@deffnx procedure partition! @var{pred} @var{list}
@deffnx procedure delete @var{x} @var{list} @r{[}@var{=}@r{]}
@deffnx procedure delete! @var{x} @var{list} @r{[}@var{=}@r{]}
@deffnx procedure remq @var{x} @var{list}
@end deffn

@deffn procedure concatenate @var{list-of-lists} @r{[}@var{separator}@r{]}
Expand Down Expand Up @@ -5512,6 +5517,9 @@ The procedures in this section are not yet documented.
@deffn procedure reverse! @var{list}
@end deffn

@deffn procedure append! @var{list}@dots{}
@end deffn

@deffn procedure append-reverse @var{list} @var{tail}
@deffnx procedure append-reverse! @var{list} @var{tail}
@end deffn
Expand All @@ -5521,7 +5529,12 @@ The procedures in this section are not yet documented.

@deffn procedure take @var{x} @var{i}
@deffnx procedure drop @var{x} @var{i}
@deffnx procedure take-right @var{flist} @var{i}
@deffnx procedure drop-right @var{flist} @var{i}
@deffnx procedure take! @var{x} @var{i}
@deffnx procedure drop-right! @var{flist} @var{i}
@deffnx procedure split-at @var{x} @var{i}
@deffnx procedure split-at! @var{x} @var{i}
@end deffn

@deffn procedure last @var{pair}
Expand All @@ -5533,6 +5546,7 @@ The procedures in this section are not yet documented.
@end deffn

@deffn procedure any @var{pred} @var{clist1} @var{clist2} @dots{}
@deffnx procedure every @var{pred} @var{clist1} @var{clist2} @dots{}
@end deffn

@deffn procedure char-set? @var{object}
Expand Down
12 changes: 11 additions & 1 deletion lib/_gambit#.scm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

;;; File: "_gambit#.scm"

;;; Copyright (c) 1994-2022 by Marc Feeley, All Rights Reserved.
;;; Copyright (c) 1994-2023 by Marc Feeley, All Rights Reserved.

;;;============================================================================

Expand Down Expand Up @@ -882,6 +882,16 @@
(else
expr))))))))

(macro-define-syntax macro-auto-force
(lambda (stx)
(syntax-case stx ()
((_ expr)
#'(cond-expand
(enable-auto-forcing
(##force expr))
(else
expr))))))

(macro-define-syntax macro-if-checks
(lambda (stx)
(syntax-case stx ()
Expand Down
5 changes: 5 additions & 0 deletions lib/_std#.scm
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@
(macro-fail-check-proper-or-circular-list ,arg-id ,form)))
,expr))

;; The finite-list type excludes circular lists.

(define-check-type (list finite-list) #f
(lambda (obj) #t)) ;; defer detailed checks to logic traversing the list

;;; Pair types.

(define-check-type pair 'pair
Expand Down
12 changes: 12 additions & 0 deletions lib/gambit#.scm
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ all-bits-set?
any
any-bit-set?
any-bits-set?
append!
append-reverse
append-reverse!
apropos
Expand Down Expand Up @@ -205,6 +206,8 @@ dead-end
deadlock-exception?
default-user-interrupt-handler
defer-user-interrupts
delete
delete!
delete-directory
delete-file-or-directory
directory-files
Expand All @@ -219,6 +222,8 @@ divide-by-zero-exception-procedure
divide-by-zero-exception?
dotted-list?
drop
drop-right
drop-right!
eighth
end-of-char-set?
eq?-hash
Expand All @@ -232,6 +237,7 @@ error-exception?
euclidean-quotient
euclidean-remainder
euclidean/
every
every-bit-set?
executable-path
expression-parsing-exception-kind
Expand Down Expand Up @@ -299,6 +305,7 @@ file-owner
file-size
file-type
filter
filter!
first
first-set-bit
fixnum->flonum
Expand Down Expand Up @@ -602,6 +609,7 @@ output-port-readtable-set!
output-port-timeout-set!
output-port-width
partition
partition!
path-directory
path-expand
path-extension
Expand Down Expand Up @@ -685,6 +693,7 @@ readtable-write-extended-read-macros?-set
readtable?
real-time
remove
remove!
remq
rename-file
repl-backtrace-detail-level
Expand Down Expand Up @@ -882,6 +891,7 @@ socket-info-family
socket-info-port-number
socket-info?
split-at
split-at!
stack-overflow-exception?
started-thread-exception-arguments
started-thread-exception-procedure
Expand Down Expand Up @@ -963,6 +973,8 @@ table-search
table-set!
table?
take
take!
take-right
tanh
tcp-client-local-socket-info
tcp-client-peer-socket-info
Expand Down
14 changes: 13 additions & 1 deletion lib/gambit/gambit.sld
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ open-input-file
open-output-file
output-port?
pair?
partition
peek-char
positive?
procedure?
Expand Down Expand Up @@ -417,6 +416,7 @@ all-bits-set?
any
any-bit-set?
any-bits-set?
append!
append-reverse
append-reverse!
apropos
Expand Down Expand Up @@ -561,6 +561,8 @@ dead-end
deadlock-exception?
default-user-interrupt-handler
defer-user-interrupts
delete
delete!
delete-directory
delete-file-or-directory
directory-files
Expand All @@ -575,6 +577,8 @@ divide-by-zero-exception-procedure
divide-by-zero-exception?
dotted-list?
drop
drop-right
drop-right!
eighth
end-of-char-set?
eq?-hash
Expand All @@ -585,6 +589,7 @@ error
error-exception-message
error-exception-parameters
error-exception?
every
every-bit-set?
executable-path
expression-parsing-exception-kind
Expand Down Expand Up @@ -652,6 +657,7 @@ file-owner
file-size
file-type
filter
filter!
first
first-set-bit
fixnum->flonum
Expand Down Expand Up @@ -954,6 +960,8 @@ output-port-readtable
output-port-readtable-set!
output-port-timeout-set!
output-port-width
partition
partition!
path-directory
path-expand
path-extension
Expand Down Expand Up @@ -1037,6 +1045,7 @@ readtable-write-extended-read-macros?-set
readtable?
real-time
remove
remove!
remq
rename-file
repl-backtrace-detail-level
Expand Down Expand Up @@ -1231,6 +1240,7 @@ socket-info-family
socket-info-port-number
socket-info?
split-at
split-at!
stack-overflow-exception?
started-thread-exception-arguments
started-thread-exception-procedure
Expand Down Expand Up @@ -1312,6 +1322,8 @@ table-search
table-set!
table?
take
take!
take-right
tanh
tcp-client-local-socket-info
tcp-client-peer-socket-info
Expand Down
Loading

3 comments on commit 9aadef4

@gambiteer
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is interesting. One idea that came to mind:

Now that you've implemented some "bang" procedures using set-car! and set-cdr!, you naturally require the associated pairs to be mutable. (And not all pairs in the list, just some.)

If the "bang" procedures had simply been implemented the same as the non-"bang" procedures then you wouldn't need mutability of the pair. So your implementation choice turns what might be a non-error in another implementation of the library into an error in this implementation of the library.

I don't remember this coming up in the SRFI 1 discussion (so many years ago!). The term "mutable" does not appear in the text of the SRFI specification.

@gambiteer
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just checked Racket's SRFI libraries at https://github.com/racket/srfi
The ! routines from Olin's code are commented out, with notes that lists are immutable in Racket; the ! routines are just renamed from the non-! versions.
That makes sense for Racket; I'm not sure yet what makes sense for Gambit.

@gambiteer
Copy link
Collaborator

@gambiteer gambiteer commented on 9aadef4 Jan 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And Olin's original code for filter! (or any other ! routine that takes a predicate) is not call/cc-safe.
Edit: But now I realize that all the discussion of "linear update" procedures in SRFI 1 is for this case---if a predicate captures the continuation that has a reference to one of the list arguments, then it's not programming in a "linear update" way.

Please sign in to comment.