Skip to content

Commit 886f149

Browse files
committed
Core update: Add null coalesce feature to core language.
1 parent 92fc2cc commit 886f149

File tree

6 files changed

+24
-1
lines changed

6 files changed

+24
-1
lines changed

base.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,18 @@ ctr_object* ctr_nil_to_string(ctr_object* myself, ctr_argument* argumentList) {
115115
return ctr_build_string_from_cstring( CTR_DICT_NIL );
116116
}
117117

118+
/**
119+
* @def
120+
* [ Nil ] else: [ Object ]
121+
*
122+
* @example
123+
* ☞ x ≔ Nil.
124+
* ✎ write: (x else: 123), stop.
125+
*/
126+
ctr_object* ctr_nil_else_set(ctr_object* myself, ctr_argument* argumentList) {
127+
return argumentList->object;
128+
}
129+
118130
/**
119131
* @def
120132
* [ Nil ] number

citrine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ extern ctr_object* ctr_nil_is_nil(ctr_object* myself, ctr_argument* argumentList
441441
extern ctr_object* ctr_nil_to_string(ctr_object* myself, ctr_argument* argumentList);
442442
extern ctr_object* ctr_nil_to_number(ctr_object* myself, ctr_argument* argumentList);
443443
extern ctr_object* ctr_nil_to_boolean(ctr_object* myself, ctr_argument* argumentList);
444+
extern ctr_object* ctr_nil_else_set(ctr_object* myself, ctr_argument* argumentList);
444445

445446
/**
446447
* Object Interface

tests/exp/xx2/test0372.exp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1
2+
2
3+
3

tests/test-o-mat/Configuration

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@
3131
☞ one way languages ≔ List ← ‘hy’ ; ‘en’.
3232

3333
☞ variations ≔ memory management modes + languages.
34-
☞ number of tests ≔ 371.
34+
☞ number of tests ≔ 372.
3535

3636
☞ base path for tests ≔ ‘../../’.

tests/test0372.ctr

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
‘SINGLE_LANGUAGE’.
2+
✎ write: (Nil else: 1), stop.
3+
✎ write: (Nil else: Nil, else: 2), stop.
4+
✎ write: (Nil else: Nil, else: Nil, else: 3), stop.
5+
6+

world.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,7 @@ void ctr_initialize_world() {
689689
ctr_internal_create_func( CtrStdNil, ctr_build_string_from_cstring( CTR_DICT_TONUMBER ), &ctr_nil_to_number );
690690
ctr_internal_create_func( CtrStdNil, ctr_build_string_from_cstring( CTR_DICT_TOBOOL ), &ctr_nil_to_boolean );
691691
ctr_internal_create_func( CtrStdNil, ctr_build_string_from_cstring( CTR_DICT_CODE ), &ctr_nil_to_string );
692+
ctr_internal_create_func( CtrStdNil, ctr_build_string_from_cstring( CTR_DICT_ELSE ), &ctr_nil_else_set );
692693
CtrStdNil->link = CtrStdObject;
693694
CtrStdNil->info.sticky = 1;
694695

0 commit comments

Comments
 (0)