Skip to content

Commit 0c7bebd

Browse files
committed
CHANGE: replace bind? and bound? with context?
resolves: Oldes/Rebol-issues#2440 resolves: Oldes/Rebol-issues#886 related to: Oldes/Rebol-issues#196 related to: Oldes/Rebol-issues#2076
1 parent 6fc8732 commit 0c7bebd

File tree

5 files changed

+33
-8
lines changed

5 files changed

+33
-8
lines changed

src/boot/natives.reb

+3-2
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,10 @@ unbind: native [
370370
/deep "Process nested blocks"
371371
]
372372

373-
bound?: native [
373+
context?: native [ ; was originally named `bound?`
374374
{Returns the context in which a word is bound.}
375-
word [any-word!]
375+
word [any-word!] "Word to check."
376+
;return: [object! function! none!]
376377
]
377378

378379
collect-words: native [

src/core/n-data.c

+10-3
Original file line numberDiff line numberDiff line change
@@ -328,15 +328,22 @@ static int Check_Char_Range(REBVAL *val, REBINT limit)
328328

329329
/***********************************************************************
330330
**
331-
*/ REBNATIVE(boundq)
331+
*/ REBNATIVE(contextq)
332332
/*
333+
** Originally named `boundq`
334+
** see: https://github.com/Oldes/Rebol-issues/issues/2440
335+
**
333336
***********************************************************************/
334337
{
335338
REBVAL *word = D_ARG(1);
336339

337340
if (!HAS_FRAME(word)) return R_NONE;
338-
if (VAL_WORD_INDEX(word) < 0) return R_TRUE;
339-
SET_OBJECT(D_RET, VAL_WORD_FRAME(word));
341+
if (VAL_WORD_INDEX(word) < 0) {
342+
// was originally returning R_TRUE for function context
343+
*D_RET = Stack_Frame(1)[3];
344+
} else {
345+
SET_OBJECT(D_RET, VAL_WORD_FRAME(word));
346+
}
340347
return R_RET;
341348
}
342349

src/mezz/base-constants.reb

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@ max: :maximum
5858
abs: :absolute
5959
empty?: :tail?
6060
---: :comment
61-
bind?: :bound?
61+
;bind?: :bound? ;@@ https://github.com/Oldes/Rebol-issues/issues/2440
6262

6363
rebol.com: http://www.rebol.com

src/tests/units/func-test.r3

+18-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,21 @@ Rebol [
6666
===end-group===
6767

6868

69+
===start-group=== "function's context?"
70+
--test-- "wish-2440"
71+
;@@ https://github.com/Oldes/Rebol-issues/issues/2440
72+
f: func[arg1 arg2][context? 'arg1]
73+
--assert same? :f f 1 2
74+
f: func[arg1 arg2][spec-of context? 'arg1]
75+
--assert [arg1 arg2] = f 1 2
76+
f: func[arg1 arg2 /local f2][
77+
f2: func[a][spec-of context? 'a]
78+
f2 arg1
79+
]
80+
--assert [a] = f 1 2
81+
===end-group===
82+
83+
6984
===start-group=== "types-of"
7085

7186
--test-- "types-of FUNCTION"
@@ -188,7 +203,9 @@ Rebol [
188203

189204
--test-- "issue-196"
190205
;@@ https://github.com/Oldes/Rebol-issues/issues/196
191-
--assert do func [a] [bind? 'a] 1 ;-no crash
206+
; with change related to https://github.com/Oldes/Rebol-issues/issues/2440
207+
; bellow test is now throwing error instead of `true`
208+
--assert error? try [do func [a] [context? 'a] 1] ;-no crash
192209

193210
--test-- "issue-216"
194211
;@@ https://github.com/Oldes/Rebol-issues/issues/216

src/tests/units/object-test.r3

+1-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ Rebol [
331331
===start-group=== "USE"
332332
--test-- "issue-197"
333333
;@@ https://github.com/Oldes/Rebol-issues/issues/197
334-
--assert object? o: use [a] [bind? 'a]
334+
--assert object? o: use [a] [context? 'a]
335335
--assert [a] = words-of o
336336

337337
===end-group===

0 commit comments

Comments
 (0)