ForthHub / forth

:four_leaf_clover: Forth engine in JavaScript
MIT License
60 stars 8 forks source link

>IN #10

Open drom opened 8 years ago

drom commented 8 years ago

The following code:

VARIABLE SCANS
: RESCAN?  -1 SCANS +! SCANS @ IF 0 >IN ! THEN ;

T{ 2 SCANS !
345 RESCAN?
-> 345 345 }T

: GS2  5 SCANS ! S" 123 RESCAN?" EVALUATE ;
T{ GS2 -> 123 123 123 123 123 }T

: GS3 WORD COUNT SWAP C@ ;
T{ BL GS3 HELLO -> 5 CHAR H }T
T{ CHAR " GS3 GOODBYE" -> 7 CHAR G }T
T{ BL GS3
DROP -> 0 }T                \ BLANK LINE RETURN ZERO-LENGTH STRING

: GS4 SOURCE >IN ! DROP ;
T{ GS4 123 456
-> }T

Yields the errors:

Error: in line: 797 -> 345 345 }T  expected [ 837 ] to deeply equal [ 837, 837 ].
Error: in line: 800 T{ GS2 -> 123 123 123 123 123 }T  expected [ 291 ] to deeply equal [ 291, 291, 291, 291, 291 ].
Error: in line: 803 T{ BL GS3 HELLO -> 5 CHAR H }T  expected [ 72, 69 ] to deeply equal [ 5, 72 ].
Error: in line: 804 T{ CHAR " GS3 GOODBYE" -> 7 CHAR G }T  expected [ 71, 79 ] to deeply equal [ 7, 71 ].
Error: in line: 805 T{ BL GS3 DROP -> 0 }T       expected [ 68, 82 ] to deeply equal [ 0 ].
Error: in line: 810 -> }T  expected [ 291, 1110 ] to deeply equal [].