(buggy? out of date?) example in TBOS?

63 vistas
Ir al primer mensaje no leído

Joel McCracken

no leída,
24 nov 2022, 2:53:41 a.m.24/11/22
para Shen
I'm looking at this page in TBOS: https://shenlanguage.org/TBoS/tbos_249.html. The text indicates that a left rule is needed in order to infer that the elements in the record list are of type name, age, department, respectively.

However, when  I try the code, it does not seem that I *need* to actually write that L rule. I also copied the code from here: https://shenlanguage.org/TBOS/Programs/19.2.txt (which is slightly different from the text) and converted the equals to underscores and the get-age function still type checked.

Am I doing something wrong? Could it be because I'm using the scheme port?

Thanks, I've been finding Shen to be one of the most mind blowing things I've encountered in perhaps my entire career.


Here is my code:

(datatype age

 if (number? Age)
 if (>= Age 18)
 if (<= Age 64)
 ____________
 Age : age;)

(datatype department

if (element? D [wages recruitment sales advertising])
____________________________________________________
D : department;)

(datatype record
N : string; A : age; D : department;
____________________________________
[N A D] : record;)

(define get-age
 {string --> (list record) --> age}
 _ [] -> (error "no details for this name~%")
 N [[N A D] | _] -> A
 N [_ | Records] -> (get-age N Records))

(get-age "hank" [["hank" 26 sales]])


I am running this code with the following command:


[255] joel@glamdring> ~/Downloads/shen-scheme-v0.25.3-macOS-bin/bin/shen-scheme eval -e "(tc +)" -l foo.shen
true
true : boolean
age#type : symbol
department#type : symbol
record#type : symbol
(fn get-age) : (string --> ((list record) --> age))
26 : age

run time: 0.017623 secs

typechecked in 323 inferences
joel@glamdring>                                                               ~/Downloads/tmp

Mark Tarver

no leída,
26 nov 2022, 8:17:44 p.m.26/11/22
para Shen
No; TBOS is right.  There is a bug in the kernel which requires about 4 lines
of code to put right.  I'll patch this over the cloud in SP and see.

Mark

Mark Tarver

no leída,
26 nov 2022, 8:30:54 p.m.26/11/22
para Shen
Shen, copyright (C) 2010-2020 Mark Tarver
www.shenlanguage.org, Shen Professional Edition 33.03
running under Common Lisp, implementation: SBCL
port 3.2 ported by Mark Tarver
commercially licensed to Mark Tarver


(0-) (datatype age


 if (number? Age)
 if (>= Age 18)
 if (<= Age 64)
 ____________
 Age : age;)
age#type

(1-)

(datatype department

if (element? D [wages recruitment sales advertising])
____________________________________________________
D : department;)
department#type

(2-)

(datatype record
N : string; A : age; D : department;
____________________________________
[N A D] : record;)
record#type

(3+) (define get-age

 {string --> (list record) --> age}
 _ [] -> (error "no details for this name~%")
 N [[N A D] | _] -> A
 N [_ | Records] -> (get-age N Records))
type error in rule 2 of get-age

(4+) (datatype record


N : string; A : age; D : department;
====================================

[N A D] : record;)
record#type : symbol

(6+) !3

(define get-age
 {string --> (list record) --> age}
 _ [] -> (error "no details for this name~%")
 N [[N A D] | _] -> A
 N [_ | Records] -> (get-age N Records))
(fn get-age) : (string --> ((list record) --> age))

This passes all the standard tests for the kernel and is now in SP.
Kernel revision will appear soon.

Mark

Joel McCracken

no leída,
27 nov 2022, 9:10:48 p.m.27/11/22
para Shen
Not sure whats going on, but I downloaded the latest release of shen-scheme and it seems like the problem still exists. Is it possible that I need to update something somewhere else?


[255] joel@glamdring> ~/Downloads/shen-scheme-v0.28-macOS-bin/bin/shen-scheme eval -l foo.shen                                                                                             ~/Downloads/tmp
true
age#type
department#type
record#type
(fn get-age)
27

run time: 0.017005999999999993 secs
joel@glamdring> cat foo.shen                                                                                                                                                               ~/Downloads/tmp
(tc +)


(datatype age
 if (number? Age)
 if (>= Age 18)
 if (<= Age 64)
 ____________
 Age : age;)

(datatype department

if (element? D [wages recruitment sales advertising])
____________________________________________________
D : department;)


(datatype record
N : string; A : age; D : department;
____________________________________
[N A D] : record;)

(define get-age
{string --> (list record) --> age}
_ [] -> (error "no details for this name~%")
N [[N A D] | _] -> A
N [_ | Records] -> (get-age N Records))



(get-age "hank" [["hank" 27 sales]])

Bruno Deferrari

no leída,
27 nov 2022, 10:17:52 p.m.27/11/22
para qil...@googlegroups.com
You need to evaluate "(tc +)" before loading a file if you want it to be typechecked, because by the time the "(tc +)" expression gets evaluated to enable type checking, the file will have been read already.

Try:

$ shen-scheme eval -e "(tc +)" -l foo.shen


--
You received this message because you are subscribed to the Google Groups "Shen" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qilang+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/qilang/4eaf30da-6222-4499-8935-d7963afb9bfen%40googlegroups.com.


--
BD

Joel McCracken

no leída,
28 nov 2022, 1:43:04 a.m.28/11/22
para qil...@googlegroups.com
That was it, thank you and sorry! Even tho I had been doing that before, I hadn't realized it was actually necessary.

Joel

Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos