On Sunday, December 18, 2016 at 6:12:26 PM UTC-6, rickman wrote:
> From wikipedia...
>
> "There exist differing conventions concerning the unary operator −
> (usually read "minus").
Python has an unary operator - , as demonstrated:
$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> -4
-4
>>> --4
4
>>> ---4
-4
>>> ----4
4
Forth does not have this operator:
$ gforth -e '-4 . cr bye'
-4
$ gforth -e '--4 . cr bye' # why you confuse things?
4
$ gforth -e '---4 . cr bye'
*OS command line*:-1: Undefined word
>>>---4<<< . cr bye
Backtrace:
$7F16288A5A68 throw
$7F16288BBCE0 no.extensions
$7F16288A5D28 interpreter-notfound1
$ sf -4 . bye
-4
$ sf --4 . . bye # interpreted as a double number
-1 -4
$ sf ---4 . . bye
-1 -4
$ vfxlin -4 . bye
4
$ vfxlin --4 . bye
Err# -13 ERR: Undefined word.
Source: "/VFXBase/Vfx2.BLD" on line 0
->
^
ERROR on command line
Received SIGHUP or SIGTERM
In Forth the leading - is just part of how a number is expressed.
Some other languages use _ for Forth's purposes, and - for Python's.
O'Caml is an example of an infix language that has unary - but still
observably treats - in literals as part of the number, but then
*still* confuses things by giving unary - (and -.) higher precedence:
# let x = 2;;
val x : int = 2
# -x;; <- unary - truly exists
- : int = -2
# -2;;
- : int = -2
# --2;; <- that's not two of unary -
Error: Syntax error
# - - 2;;
- : int = 2
# -2.0**2.0;; <- shown below, this REALLY isn't unary -
- : float = 4.
# let x = 2.0;;
val x : float = 2.
# -x**2.0;;
Error: This expression has type float but an expression was expected of type
int
# -x;;
Error: This expression has type float but an expression was expected of type
int
# -.x;; <- unary -. (dot for float)
- : float = -2.
# -.x**2.0;;
- : float = 4.
-- Julian