diff --git a/Goldfish.tmu b/Goldfish.tmu index f7656892b06feaed67981a6886b9c171f7c735a7..e31ba424c040a5c0a02ad5c6ada44a745fe3a061 100644 --- a/Goldfish.tmu +++ b/Goldfish.tmu @@ -253,7 +253,21 @@ - Goldfish Scheme解释器默认会加载。 + \; + + Goldfish Scheme解释器默认会加载。如果不想默认加载,请使用s7、r7rs或者sicp模式。 + + 由以下函数库组成: + + <\description> + 由R7RS定义的Scheme基础函数库 + + 由SRFI-2定义的 + + 由SRFI-8定义的 + + 三鲤扩展函数和S7内置的非R7RS函数,例如 + @@ -424,7 +438,9 @@ (import (scheme base) - \ \ \ \ \ \ \ \ (srfi srfi-2)) + \ \ \ \ \ \ \ \ (srfi srfi-2) + + \ \ \ \ \ \ \ \ (srfi srfi-8)) (export @@ -480,6 +496,10 @@ \ \ and-let* + \ \ ; SRFI-8 + + \ \ receive + \ \ ; Extra routines for (liii base) \ \ == != display* in? let1 compose identity typed-lambda @@ -1573,6 +1593,130 @@ \; + + + 官网: + + 官网的参考实现是: + + <\scm-code> + (define-syntax receive + + \ \ (syntax-rules () + + \ \ \ \ ((receive formals expression body ...) + + \ \ \ \ \ (call-with-values (lambda () expression) + + \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (lambda formals body ...))))) + + + 但是S7 Scheme里面没有define-syntax和syntax-rule,在墨干中的实现是这样的: + + <\session|goldfish|default> + <\folded-io> + \\ + <|folded-io> + (define-macro (receive vars vals . body) + + \ \ ‘((lambda ,vars ,@body) ,vals)) ; GPL + <|folded-io> + receive + + + <\folded-io> + \\ + <|folded-io> + (receive (a b) (values 1 2) (+ a b)) + <|folded-io> + 3 + + + <\folded-io> + \\ + <|folded-io> + ((lambda (a b) (+ a b)) 1 2) + <|folded-io> + 3 + + + <\input> + \\ + <|input> + \; + + + + S7里面有,使用就可以实现SRFI-8。 + + <\scm-chunk|goldfish/srfi/srfi-8.scm|false|false> + ; + + ; Copyright (C) 2024 The Goldfish Scheme Authors + + ; + + ; Licensed under the Apache License, Version 2.0 (the "License"); + + ; you may not use this file except in compliance with the License. + + ; You may obtain a copy of the License at + + ; + + ; http://www.apache.org/licenses/LICENSE-2.0 + + ; + + ; Unless required by applicable law or agreed to in writing, software + + ; distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + + ; WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + + ; License for the specific language governing permissions and limitations + + ; under the License. + + ; + + \; + + (define-library (srfi srfi-8) + + (export receive) \ \ \ \ \ \ \ \ \ \ \ \ \ + + (begin + + \; + + (define-macro (receive formals expression . body) + + \ \ ‘(call-with-values + + \ \ \ \ (lambda () (values ,expression)) + + \ \ \ \ (lambda ,formals ,@body))) + + \; + + ) ; end of begin + + ) ; end of define-library + + \; + + + <\scm-chunk|tests/goldfish/liii/base-test.scm|true|true> + (check + + \ \ (receive (a b) (values 1 2) (+ a b)) + + \ \ =\ 3) + + \; + + @@ -12737,182 +12881,6 @@ \; - - - \; - - 官网: - - 官网的参考实现是: - - <\scm-code> - (define-syntax receive - - \ \ (syntax-rules () - - \ \ \ \ ((receive formals expression body ...) - - \ \ \ \ \ (call-with-values (lambda () expression) - - \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (lambda formals body ...))))) - - - 但是S7 Scheme里面没有define-syntax和syntax-rule,在墨干中的实现是这样的: - - <\session|goldfish|default> - <\folded-io> - \\ - <|folded-io> - (define-macro (receive vars vals . body) - - \ \ ‘((lambda ,vars ,@body) ,vals)) ; GPL - <|folded-io> - receive - - - <\folded-io> - \\ - <|folded-io> - (receive (a b) (values 1 2) (+ a b)) - <|folded-io> - 3 - - - <\folded-io> - \\ - <|folded-io> - ((lambda (a b) (+ a b)) 1 2) - <|folded-io> - 3 - - - <\input> - \\ - <|input> - \; - - - - S7里面有,使用就可以实现SRFI-8。 - - <\scm-chunk|goldfish/srfi/srfi-8.scm|false|false> - ; - - ; Copyright (C) 2024 The Goldfish Scheme Authors - - ; - - ; Licensed under the Apache License, Version 2.0 (the "License"); - - ; you may not use this file except in compliance with the License. - - ; You may obtain a copy of the License at - - ; - - ; http://www.apache.org/licenses/LICENSE-2.0 - - ; - - ; Unless required by applicable law or agreed to in writing, software - - ; distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - - ; WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - - ; License for the specific language governing permissions and limitations - - ; under the License. - - ; - - \; - - (define-library (srfi srfi-8) - - (export receive) \ \ \ \ \ \ \ \ \ \ \ \ \ - - (begin - - \; - - (define-macro (receive formals expression . body) - - \ \ ‘(call-with-values - - \ \ \ \ (lambda () (values ,expression)) - - \ \ \ \ (lambda ,formals ,@body))) - - \; - - ) ; end of begin - - ) ; end of define-library - - \; - - - \; - - <\scm-chunk|tests/goldfish/srfi/srfi-8-test.scm|false|false> - ; - - ; Copyright (C) 2024 The Goldfish Scheme Authors - - ; - - ; Licensed under the Apache License, Version 2.0 (the "License"); - - ; you may not use this file except in compliance with the License. - - ; You may obtain a copy of the License at - - ; - - ; http://www.apache.org/licenses/LICENSE-2.0 - - ; - - ; Unless required by applicable law or agreed to in writing, software - - ; distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - - ; WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - - ; License for the specific language governing permissions and limitations - - ; under the License. - - ; - - \; - - (import (srfi srfi-8) - - \ \ \ \ \ \ \ \ (liii check)) - - \; - - (check-set-mode! 'report-failed) - - \; - - (check - - \ \ (receive (a b) (values 1 2) (+ a b)) - - \ \ =\ - - \ \ 3) - - \; - - (check-report) - - \; - - diff --git a/goldfish/liii/base.scm b/goldfish/liii/base.scm index 16ca1981da409a8706e35be60114b1234dec031a..9abf7dd707266747e9bb3238715755095cb7d02d 100644 --- a/goldfish/liii/base.scm +++ b/goldfish/liii/base.scm @@ -16,7 +16,8 @@ (define-library (liii base) (import (scheme base) - (srfi srfi-2)) + (srfi srfi-2) + (srfi srfi-8)) (export ; (scheme base) defined by R7RS let-values @@ -44,6 +45,8 @@ raise guard read-error? file-error? ; SRFI-2 and-let* + ; SRFI-8 + receive ; Extra routines for (liii base) == != display* in? let1 compose identity typed-lambda ) diff --git a/tests/goldfish/liii/base-test.scm b/tests/goldfish/liii/base-test.scm index e6fa760d8aa9c3bc4eee69d891c96371c9702deb..7d06b332d6023843cccde6c297e20b331de65b2a 100644 --- a/tests/goldfish/liii/base-test.scm +++ b/tests/goldfish/liii/base-test.scm @@ -246,6 +246,10 @@ (check (*) => 1) (check (call-with-values * -) => -1) +(check + (receive (a b) (values 1 2) (+ a b)) + => 3) + (guard (condition (else (display "condition: ") diff --git a/tests/goldfish/srfi/srfi-8-test.scm b/tests/goldfish/srfi/srfi-8-test.scm deleted file mode 100644 index 0ecc155ad8e42511fcabf5fcc2a8a53fab225e35..0000000000000000000000000000000000000000 --- a/tests/goldfish/srfi/srfi-8-test.scm +++ /dev/null @@ -1,28 +0,0 @@ -; -; Copyright (C) 2024 The Goldfish Scheme Authors -; -; Licensed under the Apache License, Version 2.0 (the "License"); -; you may not use this file except in compliance with the License. -; You may obtain a copy of the License at -; -; http://www.apache.org/licenses/LICENSE-2.0 -; -; Unless required by applicable law or agreed to in writing, software -; distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -; WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -; License for the specific language governing permissions and limitations -; under the License. -; - -(import (srfi srfi-8) - (liii check)) - -(check-set-mode! 'report-failed) - -(check - (receive (a b) (values 1 2) (+ a b)) - => - 3) - -(check-report) -