Skip to content

Commit

Permalink
Switch to NIHIL as results for PRINT, HELP, etc.
Browse files Browse the repository at this point in the history
When a function doesn't have an "interesting" result, there
are tradeoffs for the choices of what to return.

* VOID has the positive property of making no console
  output, but the negative property of being too widely
  tolerated as an "interesting" way of opting out of a
  parameter.

* Things like NULL and NONE are good for their "disruptive"
  nature, but have the downside of making confusing-looking
  console output which mixes in with the intended output.
  It's a bit ugly, and will make beginners scratch their
  head when using functions like PRINT or HELP.

* NIHIL is the means of vaporizing completely--used by
  functions like COMMENT and ELIDE.  It is slightly unfriendly
  in the sense it cannot be used in assignments or passed as
  an argument to nearly all functions (excluding things like
  RETURN), but may lead to behavior that might seem mysterious
  by preserving the last result in an evaluation chain.

I'd been reticent to make too many invisible functions in the
core, preferring that people write ELIDE PRINT if they really
wanted to erase the return value from PRINT.  But as it became
clear that VOID was truly the best choice for making no
console output, and no console output would be output from
something like `do [comment "hi"]`, the fact that the evaluator
would be based on DO meant that usage of an expression that
was solely an invisible would wind up appearing VOID while
having some ornery properties.

From a marketing perspective, the choice of NIHIL as the
return result from functions like PRINT and HELP simply could
not be avoided.  This buries the hatchet and makes that choice.
  • Loading branch information
hostilefork committed Sep 14, 2023
1 parent d4cf347 commit ecb0534
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
22 changes: 13 additions & 9 deletions src/mezz/base-defs.r
Original file line number Diff line number Diff line change
Expand Up @@ -561,33 +561,36 @@ to-lit-path: func* [return: [quoted!] value [any-value!]] [
]

print: func* [
{Textually output spaced line (evaluating elements if a block)}
{Output SPACED text with newline (evaluating elements if BLOCK!)}

return: "NULL if blank input or effectively empty block, else none"
[<opt> none!]
line "Line of text or block, blank or [] has NO output, newline allowed"
return: "See NIHIL docs for caution on casually making vaporizing routines"
[<nihil>]
line "Line of text or block, [] has NO output, CHAR! newline allowed"
[<maybe> char! text! block! quoted!]
][
if char? line [
if line <> newline [
fail "PRINT only allows CHAR! of newline (see WRITE-STDOUT)"
]
return write-stdout line
write-stdout line
return nihil
]

if quoted? line [ ; Feature: treats a quote mark as a mold request
if quoted? line [ ; Speculative feature: quote mark as a mold request
line: mold unquote line
]

return write-stdout (maybe spaced line) then [
write-stdout (maybe spaced line) then [
write-stdout newline
] else [none]
]

return nihil
]

echo: func* [
{Freeform output of text, with @WORD, @TU.P.LE, and @(GR O UP) as escapes}

return: <void>
return: [<nihil>]
'args "If a BLOCK!, then just that block's contents--else to end of line"
[any-value! <variadic>]
<local> line
Expand All @@ -614,6 +617,7 @@ echo: func* [
]
]
write-stdout newline
return nihil
]


Expand Down
32 changes: 16 additions & 16 deletions src/mezz/mezz-help.r
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ browse: function [
help: function [
"Prints information about words and values (if no args, general help)."

return: <void>
return: [<nihil>]
'topic [<end> any-value!]
"WORD! whose value to explain, or other HELP target (try HELP HELP)"
/doc "Open web browser to related documentation."
Expand Down Expand Up @@ -143,7 +143,7 @@ help: function [
upgrade - check for newer versions
usage - program cmd line options
}
return void
return nihil
]

; HELP quotes, but someone might want to use an expression, e.g.
Expand All @@ -156,7 +156,7 @@ help: function [
if match [group! get-word! get-path! get-tuple!] :topic [
topic: reeval topic else [
print "NULL is a non-valued state that cannot be put in arrays"
return void
return nihil
]
]

Expand Down Expand Up @@ -184,7 +184,7 @@ help: function [

browse join https://r3n.github.io/topics/ as text! topic
print newline
return void
return nihil
]

text! [
Expand All @@ -198,7 +198,7 @@ help: function [
] else [
print ["No information on" topic]
]
return void
return nihil
]

path! word! [
Expand All @@ -209,12 +209,12 @@ help: function [
null? binding of topic
] then [
print [topic "is an unbound WORD!"]
return void
return nihil
]

if '~attached~ = binding of topic [
print [topic "is ~attached~ to a context, but has no variable"]
return void
return nihil
]

switch/type value: get/any topic [
Expand All @@ -225,7 +225,7 @@ help: function [
print [topic "is not defined (e.g. has a NONE! value)"]
]
] then [
return void
return nihil
]
enfixed: (action? :value) and (enfixed? :value)
]
Expand All @@ -241,7 +241,7 @@ help: function [
if free? :topic [keep "a *freed*"]
keep any [mold kind of :topic, "VOID"]
]
return void
return nihil
]

; Open the web page for it?
Expand Down Expand Up @@ -288,7 +288,7 @@ help: function [
] else [
print [topic {is a datatype}]
]
return void
return nihil
]

match [action! activation!] :value else [
Expand All @@ -312,7 +312,7 @@ help: function [
]
]
]
return void
return nihil
]

; The HELP mechanics for ACTION! are more complex in Ren-C due to the
Expand Down Expand Up @@ -400,14 +400,14 @@ help: function [
print-args/indent-words refinements
]

return void
return nihil
]


source: function [
"Prints the source code for an ACTION! (if available)"

return: <void>
return: [<nihil>]
'arg [word! path! action! tag!]
][
switch/type arg [
Expand All @@ -425,7 +425,7 @@ source: function [
name: arg
f: get arg else [
print [name "is not set to a value"]
return void
return nihil
]
]
] else [
Expand All @@ -448,7 +448,7 @@ source: function [
]
]
] then [
return void
return nihil
]

; ACTION!
Expand Down Expand Up @@ -476,7 +476,7 @@ source: function [
print "...native code, no source available..."
]

return void
return nihil
]


Expand Down

0 comments on commit ecb0534

Please sign in to comment.