From d7be3b81dc56593cb0c96c556aa7bcd26a862e67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E8=BE=BE?= Date: Wed, 5 Mar 2025 06:46:50 +0000 Subject: [PATCH] !285 Seperate liii_stack.tmu from GoldfishLang.tmu --- GoldfishLang.tmu | 312 ------------------------------------------- liii_stack.tmu | 338 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 338 insertions(+), 312 deletions(-) create mode 100644 liii_stack.tmu diff --git a/GoldfishLang.tmu b/GoldfishLang.tmu index 0b2c4cfb..4bd25215 100644 --- a/GoldfishLang.tmu +++ b/GoldfishLang.tmu @@ -6732,318 +6732,6 @@ \; - - - - - - <\scm-chunk|goldfish/liii/stack.scm|false|true> - ; - - ; 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. - - ; - - \; - - - <\scm-chunk|tests/goldfish/liii/stack-test.scm|false|true> - ; - - ; 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. - - ; - - \; - - - - - <\scm-chunk|goldfish/liii/stack.scm|true|true> - (define-library (liii stack) - - (import (liii lang)) - - (export stack) - - (begin - - \; - - - - - <\goldfish-chunk|tests/goldfish/liii/stack-test.scm|true|true> - (import (liii stack) (liii check)) - - \; - - (check-set-mode! 'report-failed) - - \; - - - - - <\scm-chunk|goldfish/liii/stack.scm|true|true> - (define-case-class stack ((data list?)) - - \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ - - - - - - - <\scm-chunk|goldfish/liii/stack.scm|true|true> - (define (%length) (length data)) - - \; - - - <\scm-chunk|tests/goldfish/liii/stack-test.scm|true|true> - (check ((stack (list 1 2 3)) :length) =\ 3) - - \; - - - - - <\scm-chunk|goldfish/liii/stack.scm|true|true> - (define (%size) (length data)) - - \; - - - <\scm-chunk|tests/goldfish/liii/stack-test.scm|true|true> - (check ((stack (list 1 2 3)) :size) =\ 3) - - \; - - - - - <\scm-chunk|goldfish/liii/stack.scm|true|true> - (define (%top) - - \ \ (if (null? data) - - \ \ \ \ \ \ (error 'out-of-range) - - \ \ \ \ \ \ (car data))) - - \; - - - <\goldfish-chunk|tests/goldfish/liii/stack-test.scm|true|true> - (check ((stack (list 1 2)) :top) =\ 1) - - (check-catch 'out-of-range ((stack (list )) :top)) - - \; - - - - - - - <\scm-chunk|goldfish/liii/stack.scm|true|true> - (define (%to-list) (rich-list data)) - - \; - - - <\scm-chunk|tests/goldfish/liii/stack-test.scm|true|true> - (check ((stack (list 1 2 3)) :to-list) =\ ($ (list 1 2 3))) - - \; - - - - - - - <\scm-chunk|goldfish/liii/stack.scm|true|true> - (define (@empty) (stack (list ))) - - \; - - - <\scm-chunk|tests/goldfish/liii/stack-test.scm|true|true> - (check ((stack :empty) :length) =\ 0) - - \; - - - - - - - <\scm-chunk|goldfish/liii/stack.scm|true|true> - (chained-define (%pop) - - \ \ (if (null? data) - - \ \ \ \ \ \ (error 'out-of-range "Cannot pop from an empty stack") - - \ \ \ \ \ \ (stack (cdr data)))) - - \; - - - <\scm-chunk|tests/goldfish/liii/stack-test.scm|true|true> - (check ((stack (list 1 2)) :pop) =\ (stack (list 2))) - - (check ((stack (list 1 2 3)) :pop :pop) =\ (stack (list 3))) - - (check-catch 'out-of-range ((stack :empty) :pop)) - - \; - - - - - <\scm-chunk|goldfish/liii/stack.scm|true|true> - (chained-define (%pop!) - - \ \ (if (null? data) - - \ \ \ \ \ \ (error 'out-of-range) - - \ \ \ \ \ \ (stack (set! data (cdr data)))) - - \ \ (%this)) - - \; - - - <\scm-chunk|tests/goldfish/liii/stack-test.scm|true|true> - (let1 t (stack (list 1 2 3)) - - \ \ (check (t :pop!) =\ (stack (list 2 3))) - - \ \ (check (t :pop! :pop!) =\ (stack (list ))) - - \ \ (check-catch 'out-of-range ((stack :empty) :pop!))) - - \; - - - - - <\scm-chunk|goldfish/liii/stack.scm|true|true> - (define (%push element . es)\ - - \ \ (let1 r (stack (cons element data)) - - \ \ \ \ (if (null? es) - - \ \ \ \ \ \ \ \ r - - \ \ \ \ \ \ \ \ (apply r es)))) - - \; - - - <\scm-chunk|tests/goldfish/liii/stack-test.scm|true|true> - (let1 t (stack (list 1 2 3)) - - \ \ (check (t :push 1) =\ (stack (list 1 1 2 3))) - - \ \ (check (t :push 1 :push 1) =\ (stack (list 1 1 1 2 3)))) - - \; - - - - - <\scm-chunk|goldfish/liii/stack.scm|true|true> - (chained-define (%push! element)\ - - \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (stack (set! data (cons element data)))\ - - \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (%this)) - - \; - - - <\scm-chunk|tests/goldfish/liii/stack-test.scm|true|true> - (let1 t (stack (list 1 2 3)) - - \ \ (check (t :push! 1) =\ (stack (list 1 1 2 3))) - - \ \ (check (t :push! 1 :push! 1) =\ (stack (list 1 1 1 1 2 3))) - - \ \ (check (t :pop! :push! 2) =\ (stack (list 2 1 1 1 2 3)))) - - \; - - - - - <\scm-chunk|goldfish/liii/stack.scm|true|false> - ) ; end of define-case-class - - ) ; end of begin - - ) ; end of define-library - - \; - - - <\scm-chunk|tests/goldfish/liii/stack-test.scm|true|false> - (check-report) - - \; - <\initial> diff --git a/liii_stack.tmu b/liii_stack.tmu new file mode 100644 index 00000000..959ba2a9 --- /dev/null +++ b/liii_stack.tmu @@ -0,0 +1,338 @@ +> + +> + +<\body> + <\hide-preamble> + > + + > + + + + + + + + + <\scm-chunk|goldfish/liii/stack.scm|false|true> + ; + + ; 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. + + ; + + \; + + + <\scm-chunk|tests/goldfish/liii/stack-test.scm|false|true> + ; + + ; 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. + + ; + + \; + + + + + <\scm-chunk|goldfish/liii/stack.scm|true|true> + (define-library (liii stack) + + (import (liii lang)) + + (export stack) + + (begin + + \; + + + + + <\goldfish-chunk|tests/goldfish/liii/stack-test.scm|true|true> + (import (liii stack) (liii check)) + + \; + + (check-set-mode! 'report-failed) + + \; + + + + + <\scm-chunk|goldfish/liii/stack.scm|true|true> + (define-case-class stack ((data list?)) + + \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ + + + + + + + <\scm-chunk|goldfish/liii/stack.scm|true|true> + (define (%length) (length data)) + + \; + + + <\scm-chunk|tests/goldfish/liii/stack-test.scm|true|true> + (check ((stack (list 1 2 3)) :length) =\ 3) + + \; + + + + + <\scm-chunk|goldfish/liii/stack.scm|true|true> + (define (%size) (length data)) + + \; + + + <\scm-chunk|tests/goldfish/liii/stack-test.scm|true|true> + (check ((stack (list 1 2 3)) :size) =\ 3) + + \; + + + + + <\scm-chunk|goldfish/liii/stack.scm|true|true> + (define (%top) + + \ \ (if (null? data) + + \ \ \ \ \ \ (error 'out-of-range) + + \ \ \ \ \ \ (car data))) + + \; + + + <\goldfish-chunk|tests/goldfish/liii/stack-test.scm|true|true> + (check ((stack (list 1 2)) :top) =\ 1) + + (check-catch 'out-of-range ((stack (list )) :top)) + + \; + + + + + + + <\scm-chunk|goldfish/liii/stack.scm|true|true> + (define (%to-list) (rich-list data)) + + \; + + + <\scm-chunk|tests/goldfish/liii/stack-test.scm|true|true> + (check ((stack (list 1 2 3)) :to-list) =\ ($ (list 1 2 3))) + + \; + + + + + + + <\scm-chunk|goldfish/liii/stack.scm|true|true> + (define (@empty) (stack (list ))) + + \; + + + <\scm-chunk|tests/goldfish/liii/stack-test.scm|true|true> + (check ((stack :empty) :length) =\ 0) + + \; + + + + + + + <\scm-chunk|goldfish/liii/stack.scm|true|true> + (chained-define (%pop) + + \ \ (if (null? data) + + \ \ \ \ \ \ (error 'out-of-range "Cannot pop from an empty stack") + + \ \ \ \ \ \ (stack (cdr data)))) + + \; + + + <\scm-chunk|tests/goldfish/liii/stack-test.scm|true|true> + (check ((stack (list 1 2)) :pop) =\ (stack (list 2))) + + (check ((stack (list 1 2 3)) :pop :pop) =\ (stack (list 3))) + + (check-catch 'out-of-range ((stack :empty) :pop)) + + \; + + + + + <\scm-chunk|goldfish/liii/stack.scm|true|true> + (chained-define (%pop!) + + \ \ (if (null? data) + + \ \ \ \ \ \ (error 'out-of-range) + + \ \ \ \ \ \ (stack (set! data (cdr data)))) + + \ \ (%this)) + + \; + + + <\scm-chunk|tests/goldfish/liii/stack-test.scm|true|true> + (let1 t (stack (list 1 2 3)) + + \ \ (check (t :pop!) =\ (stack (list 2 3))) + + \ \ (check (t :pop! :pop!) =\ (stack (list ))) + + \ \ (check-catch 'out-of-range ((stack :empty) :pop!))) + + \; + + + + + <\scm-chunk|goldfish/liii/stack.scm|true|true> + (define (%push element . es)\ + + \ \ (let1 r (stack (cons element data)) + + \ \ \ \ (if (null? es) + + \ \ \ \ \ \ \ \ r + + \ \ \ \ \ \ \ \ (apply r es)))) + + \; + + + <\scm-chunk|tests/goldfish/liii/stack-test.scm|true|true> + (let1 t (stack (list 1 2 3)) + + \ \ (check (t :push 1) =\ (stack (list 1 1 2 3))) + + \ \ (check (t :push 1 :push 1) =\ (stack (list 1 1 1 2 3)))) + + \; + + + + + <\scm-chunk|goldfish/liii/stack.scm|true|true> + (chained-define (%push! element)\ + + \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (stack (set! data (cons element data)))\ + + \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (%this)) + + \; + + + <\scm-chunk|tests/goldfish/liii/stack-test.scm|true|true> + (let1 t (stack (list 1 2 3)) + + \ \ (check (t :push! 1) =\ (stack (list 1 1 2 3))) + + \ \ (check (t :push! 1 :push! 1) =\ (stack (list 1 1 1 1 2 3))) + + \ \ (check (t :pop! :push! 2) =\ (stack (list 2 1 1 1 2 3)))) + + \; + + + + + <\scm-chunk|goldfish/liii/stack.scm|true|false> + ) ; end of define-case-class + + ) ; end of begin + + ) ; end of define-library + + \; + + + <\scm-chunk|tests/goldfish/liii/stack-test.scm|true|false> + (check-report) + + \; + + + +<\initial> + <\collection> + + + + + + + + + +