diff --git a/doc/lbmref.md b/doc/lbmref.md index 3ed66302..c2dcc805 100644 --- a/doc/lbmref.md +++ b/doc/lbmref.md @@ -157,6 +157,12 @@ expression evaluates to `t`. (eq '(1 (1 2)) '(1 (1 2))) ``` +--- + +### not-eq + +`not-eq` implements the negation of eq. In other words, `(not-eq a b c)` evaluates +to the same result as `(not (eq a b c))`. --- @@ -179,6 +185,13 @@ Example of `=` comparison. ``` +--- + +### != + +The `!=` operation implements the negation of `=`. So, `(!= a b)` evaluates +to the same result as `(not (= a b))`. + --- ### > diff --git a/include/lbm_version.h b/include/lbm_version.h index ef3e02e6..d885a8bf 100644 --- a/include/lbm_version.h +++ b/include/lbm_version.h @@ -33,6 +33,13 @@ extern "C" { /*! \page changelog Changelog +Nov 9: Version 0.7.1 + - not-eq and != added. + - Corrected behaviour for eval when applied to no argument. + - lbm_memory operations are protected by mutex. + - Fixes to eval-program. + - Added multiple condition conditional function called cond. + Oct 31: Version 0.7.1 - Added optional boolean guards to pattern matches. - Built in map and reverse. diff --git a/src/tokpar.c b/src/tokpar.c index 4898c8b2..4b862a77 100644 --- a/src/tokpar.c +++ b/src/tokpar.c @@ -229,7 +229,7 @@ static char translate_escape_char(char c) { } } -int tok_string(lbm_char_channel_t *chan) { +int tok_string(lbm_char_channel_t *chan, unsigned int *string_len) { unsigned int n = 0; unsigned int len = 0; @@ -264,6 +264,7 @@ int tok_string(lbm_char_channel_t *chan) { if (r == CHANNEL_MORE) return TOKENIZER_NEED_MORE; if (c != '\"') return TOKENIZER_STRING_ERROR; + *string_len = len; n ++; return (int)n; } @@ -604,16 +605,17 @@ lbm_value lbm_get_next_token(lbm_char_channel_t *chan, bool peek) { return lbm_enc_sym(SYM_TOKENIZER_WAIT); } - n = tok_string(chan); + unsigned int string_len = 0; + n = tok_string(chan, &string_len); if (n >= 2) { if (!peek) lbm_channel_drop(chan, (unsigned int)n); // TODO: Proper error checking here! // TODO: Check if anything has to be allocated for the empty string - lbm_heap_allocate_array(&res, (unsigned int)(n-2)+1, LBM_TYPE_CHAR); + lbm_heap_allocate_array(&res, (unsigned int)(string_len+1), LBM_TYPE_CHAR); lbm_array_header_t *arr = (lbm_array_header_t*)lbm_car(res); char *data = (char *)arr->data; - memset(data, 0, (unsigned int)((n-2)+1) * sizeof(char)); - memcpy(data, sym_str, (unsigned int)(n - 2) * sizeof(char)); + memset(data, 0, (string_len+1) * sizeof(char)); + memcpy(data, sym_str, string_len * sizeof(char)); return res; } else if (n == TOKENIZER_NEED_MORE) { return lbm_enc_sym(SYM_TOKENIZER_WAIT); diff --git a/tests/test_eq_not_eq_1.lisp b/tests/test_eq_not_eq_1.lisp new file mode 100644 index 00000000..fc58ed73 --- /dev/null +++ b/tests/test_eq_not_eq_1.lisp @@ -0,0 +1,13 @@ + +(define a 10) +(define b 20) +(define c 30) + +(and (eq (not (eq a b c)) (not-eq a b c)) + (eq (not (eq a a c)) (not-eq a a c)) + (eq (not (eq a a a)) (not-eq a a a)) + (eq (not (eq b b c)) (not-eq b b c)) + (eq (not (eq b b b)) (not-eq b b b)) + (eq (not (eq c b c)) (not-eq c b c)) + (eq (not (eq c c c)) (not-eq c c c))) + diff --git a/tests/test_eq_not_eq_2.lisp b/tests/test_eq_not_eq_2.lisp new file mode 100644 index 00000000..82ece687 --- /dev/null +++ b/tests/test_eq_not_eq_2.lisp @@ -0,0 +1,11 @@ +(define a 10) +(define b 20) +(define c 30) + +(and (eq (not (= a b c)) (!= a b c)) + (eq (not (= a a c)) (!= a a c)) + (eq (not (= a a a)) (!= a a a)) + (eq (not (= b b c)) (!= b b c)) + (eq (not (= b b b)) (!= b b b)) + (eq (not (= c b c)) (!= c b c)) + (eq (not (= c c c)) (!= c c c))) diff --git a/tests/test_string_1.lisp b/tests/test_string_1.lisp new file mode 100644 index 00000000..6e22dae8 --- /dev/null +++ b/tests/test_string_1.lisp @@ -0,0 +1,4 @@ + +(and (= (array-size "apa") 4) + (= (array-size "bepa") 5) + (= (array-size "kurt1") 6))