Skip to content

Commit

Permalink
Core update: Add null coalesce feature to core language.
Browse files Browse the repository at this point in the history
  • Loading branch information
gabordemooij committed Jan 29, 2025
1 parent 92fc2cc commit 886f149
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 1 deletion.
12 changes: 12 additions & 0 deletions base.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ ctr_object* ctr_nil_to_string(ctr_object* myself, ctr_argument* argumentList) {
return ctr_build_string_from_cstring( CTR_DICT_NIL );
}

/**
* @def
* [ Nil ] else: [ Object ]
*
* @example
* ☞ x ≔ Nil.
* ✎ write: (x else: 123), stop.
*/
ctr_object* ctr_nil_else_set(ctr_object* myself, ctr_argument* argumentList) {
return argumentList->object;
}

/**
* @def
* [ Nil ] number
Expand Down
1 change: 1 addition & 0 deletions citrine.h
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ extern ctr_object* ctr_nil_is_nil(ctr_object* myself, ctr_argument* argumentList
extern ctr_object* ctr_nil_to_string(ctr_object* myself, ctr_argument* argumentList);
extern ctr_object* ctr_nil_to_number(ctr_object* myself, ctr_argument* argumentList);
extern ctr_object* ctr_nil_to_boolean(ctr_object* myself, ctr_argument* argumentList);
extern ctr_object* ctr_nil_else_set(ctr_object* myself, ctr_argument* argumentList);

/**
* Object Interface
Expand Down
3 changes: 3 additions & 0 deletions tests/exp/xx2/test0372.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1
2
3
2 changes: 1 addition & 1 deletion tests/test-o-mat/Configuration
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
☞ one way languages ≔ List ← ‘hy’ ; ‘en’.

☞ variations ≔ memory management modes + languages.
☞ number of tests ≔ 371.
☞ number of tests ≔ 372.

☞ base path for tests ≔ ‘../../’.
6 changes: 6 additions & 0 deletions tests/test0372.ctr
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
‘SINGLE_LANGUAGE’.
✎ write: (Nil else: 1), stop.
✎ write: (Nil else: Nil, else: 2), stop.
✎ write: (Nil else: Nil, else: Nil, else: 3), stop.


1 change: 1 addition & 0 deletions world.c
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@ void ctr_initialize_world() {
ctr_internal_create_func( CtrStdNil, ctr_build_string_from_cstring( CTR_DICT_TONUMBER ), &ctr_nil_to_number );
ctr_internal_create_func( CtrStdNil, ctr_build_string_from_cstring( CTR_DICT_TOBOOL ), &ctr_nil_to_boolean );
ctr_internal_create_func( CtrStdNil, ctr_build_string_from_cstring( CTR_DICT_CODE ), &ctr_nil_to_string );
ctr_internal_create_func( CtrStdNil, ctr_build_string_from_cstring( CTR_DICT_ELSE ), &ctr_nil_else_set );
CtrStdNil->link = CtrStdObject;
CtrStdNil->info.sticky = 1;

Expand Down

0 comments on commit 886f149

Please sign in to comment.