Paste: cond error

Author: Erich Ocean
Mode: factor
Date: Thu, 11 Aug 2011 07:28:38
Plain Text |
! Copyright (C) 2011 Erich Atlas Ocean.
! See http://factorcode.org/license.txt for BSD license.
USING:
    alien
    alien.c-types
    alien.libraries
    alien.syntax
    classes.struct
    io.encodings.ascii
    combinators
    kernel
    system
    owl
    math
    fry
    io prettyprint math.parser
 ;

IN: recap2houdini

: print-owl-error ( s n -- )
    {
        { [ dup 0 < ] '[ _ write ": " _ . ] }
        { [ dup OWL_NO_ERROR = ]          [ drop write ": No Error" . ] }
        { [ dup OWL_INVALID_VALUE = ]     [ drop write ": Invalid Value" . ] }
        { [ dup OWL_INVALID_ENUM = ]      [ drop write ": Invalid Enum" . ] }
        { [ dup OWL_INVALID_OPERATION = ] [ drop write ": Invalid Operation" . ] }
        '[ _ write ": 0x" write _ >hex . ]
    } cond ;

! Gets this error: Generic word infer-branch does not define a method for the array class.

Annotation: Attempted rewrite with locals (also fails)

Author: Erich Ocean
Mode: factor
Date: Thu, 11 Aug 2011 07:42:43
Plain Text |
! Copyright (C) 2011 Erich Atlas Ocean.
! See http://factorcode.org/license.txt for BSD license.
USING:
    alien
    alien.c-types
    alien.libraries
    alien.syntax
    classes.struct
    io.encodings.ascii
    combinators
    kernel
    system
    owl
    math
    fry
    io prettyprint math.parser locals
 ;

IN: recap2houdini

:: print-owl-error ( s n -- )
    {
        { [ n 0 < ] [ s write ": " n . ] }
        { [ n OWL_NO_ERROR = ]          [ s write ": No Error" . ] }
        { [ n OWL_INVALID_VALUE = ]     [ s write ": Invalid Value" . ] }
        { [ n OWL_INVALID_ENUM = ]      [ s write ": Invalid Enum" . ] }
        { [ n OWL_INVALID_OPERATION = ] [ s write ": Invalid Operation" . ] }
        [ s write ": 0x" write n >hex . ]
    } cond ;

! The input quotations to “if” don't match their expected effects

Annotation: original C code

Author: Erich Ocean
Mode: c
Date: Thu, 11 Aug 2011 07:48:03
Plain Text |
void owl_print_error(const char *s, int n)
{
    if(n < 0) printf("%s: %d\n", s, n);
    else if(n == OWL_NO_ERROR) printf("%s: No Error\n", s);
    else if(n == OWL_INVALID_VALUE) printf("%s: Invalid Value\n", s);
    else if(n == OWL_INVALID_ENUM) printf("%s: Invalid Enum\n", s);
    else if(n == OWL_INVALID_OPERATION) printf("%s: Invalid Operation\n", s);
    else printf("%s: 0x%x\n", s, n);
}

Annotation: Working code

Author: Erich Ocean
Mode: factor
Date: Thu, 11 Aug 2011 07:51:07
Plain Text |
! Copyright (C) 2011 Erich Atlas Ocean.
! See http://factorcode.org/license.txt for BSD license.
USING:
    alien
    alien.c-types
    alien.libraries
    alien.syntax
    classes.struct
    io.encodings.ascii
    combinators
    kernel
    system
    owl
    math
    fry
    io prettyprint math.parser locals
 ;

IN: recap2houdini

:: print-owl-error ( s n -- )
    {
        { [ n 0 < ] [ s write ": " write n . ] }
        { [ n OWL_NO_ERROR = ]          [ s write ": No Error" . ] }
        { [ n OWL_INVALID_VALUE = ]     [ s write ": Invalid Value" . ] }
        { [ n OWL_INVALID_ENUM = ]      [ s write ": Invalid Enum" . ] }
        { [ n OWL_INVALID_OPERATION = ] [ s write ": Invalid Operation" . ] }
        [ s write ": 0x" write n >hex . ]
    } cond ;

! Hat tip to Obvious for noticing the problem.

New Annotation

Summary:
Author:
Mode:
Body: