• Re: Why is it allowed to deduce from undefined?

    From Tristan Wibberley@tristan.wibberley+netnews2@alumni.manchester.ac.uk to comp.lang.scheme on Sat Mar 2 12:17:02 2024
    From Newsgroup: comp.lang.scheme

    On 10/11/2023 08:21, ceving wrote:
    The following looks like a contradiction to me:

    (if (if #f #f) #t #f) ;; => #t
    (equal? (if #f #f) #t) ;; => #f

    Why does Scheme allowed this? And why is it anything other than division by zero?

    In Guile:
    *There seems to be a common object available with the name
    "*unspecified*" which 'if' uses for an unspecified branch.

    * It's 'equal?' to itself as well as 'eq?' and 'eqv?' - I didn't try others.

    * It's distinct from both end-of-list and #f.

    I would expect division by zero only should 'if' be defined at least in
    part by division.

    --
    Tristan
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Tristan Wibberley@tristan.wibberley+netnews2@alumni.manchester.ac.uk to comp.lang.scheme on Sat Mar 2 12:52:27 2024
    From Newsgroup: comp.lang.scheme

    On 10/11/2023 11:33, ceving wrote:
    Maciek Godek schrieb am Freitag, 10. November 2023 um 12:07:22 UTC+1:

    R5RS says this: |If the value of an expression is said to be ``unspecified,'' then the expression must evaluate to some object without signalling an error,

    I am wondering why it has been defined this way.

    I would say the opposite should be right: it must signal an error.

    First, I'm a newbie with Scheme, so I don't know all the names and nuances.

    You're thinking of pure functional languages. In Scheme, which has a
    certain imperative essence, (if...) can give *unspecified* and you can
    signal an error in that condition. It's like 'Control.Monad.when' in
    Haskell or 'if' in C, except that it also allows you to use it like 'if'
    in Haskell if you want to.

    That makes (if...) useful for inserting conditional actions in a
    sequence of them.

    You can always give a second argument if you are slow and steady enough.

    You can write a strict (if...) that requires two arguments but you must
    use a macro, I think, rather than (define...). I think you can force all (if...) uses in your files to be so strict if you want to make sure
    you've done that everywhere but I'm not so sure scheme makes it hard to subsequently liberalise.


    --- Synchronet 3.22a-Linux NewsLink 1.2