Giter Site home page Giter Site logo

Comments (7)

eliaslfox avatar eliaslfox commented on August 26, 2024 1

That is the expected behavior.

Also you don't need call-coalton-function when calling a top-level coalton function.

from coalton.

eliaslfox avatar eliaslfox commented on August 26, 2024 1

Oh yeah. If your function has type class constraints then you can't call it from lisp, you need to use the coalton macro. call-coalton-function wouldn't work either in this case.

The "fix" is to define:

(coalton-toplevel
  (declare cube1-integer (Integer -> Integer))
  (define cube1-integer cube1))

Then cube1-integer can be called directly from lisp.

from coalton.

Izaakwltn avatar Izaakwltn commented on August 26, 2024 1

Awesome, thank you, that one works perfectly.

I'm going to add a few of these cases to the docs in the next few days, thank you for the clarity!

from coalton.

stylewarning avatar stylewarning commented on August 26, 2024

Regarding your last sentence, yes please do make a separate issue.

from coalton.

Izaakwltn avatar Izaakwltn commented on August 26, 2024

Sounds good, thanks for looking this over.

I'll weave some of these cases/behavior into the interop docs.

One last case/question: When calling a top-level coalton function with a parameter in lisp, is the example below the ideal/preferred/expected syntax:

(coalton-toplevel
  (define (cube1 x)
    (* x (* x x)))

  (define (print-cube1 x)
    (lisp String (x)
      (cl:format cl:nil "cubed: ~a" (coalton (cube1 (lisp Integer () x)))))))

I figured the main advantage to call-coalton-function is to avoid this syntax.

from coalton.

eliaslfox avatar eliaslfox commented on August 26, 2024

You can just call it directly:

(define (print-cube1 x)
    (lisp String (x)
      (cl:format cl:nil "cubed: ~a" (cube1 x))))

The point of call-coalton-function is to allow calling a potentially curried function.

from coalton.

Izaakwltn avatar Izaakwltn commented on August 26, 2024

I'm afraid that solution doesn't work on my machine, though maybe it's something in my implementation.

Compiling

  (define (print-cube1 x)
    (lisp String (x)
      (cl:format cl:nil "cubed: ~a" (cube1 x))))

Returns the error

style-warning: 
    The function CUBE1 is called with one argument, but wants exactly two.
    --> PROGN DEFUN PROGN SB-IMPL::%DEFUN SB-IMPL::%DEFUN 
    --> SB-INT:NAMED-LAMBDA FUNCTION THE PROGN BLOCK THE LET VALUES 
    ==>
      1

Fixing that warning by wrapping it in coalton:

(define (print-cube1 x)
    (lisp String (x)
      (cl:format cl:nil "cubed: ~a" (coalton (cube1 x)))))

Returns

error: 
    during macroexpansion of (COALTON (CUBE1 X)). Use
    COMMON-LISP:*BREAK-ON-SIGNALS* to intercept.
    
     error: Unknown variable
      --> COALTON (/private/var/tmp/slimepQIMm3):1:16
       |
     1 |  (COALTON (CUBE1 X))
       |                  ^ unknown variable
    
    --> PROGN DEFUN PROGN SB-IMPL::%DEFUN SB-IMPL::%DEFUN 
    --> SB-INT:NAMED-LAMBDA FUNCTION THE PROGN BLOCK THE LET VALUES 
    ==>
      1
    
  style-warning: 
    The variable X is defined but never used.
    --> PROGN DEFUN PROGN SB-IMPL::%DEFUN SB-IMPL::%DEFUN 
    --> SB-INT:NAMED-LAMBDA FUNCTION THE PROGN BLOCK THE 
    ==>
      (LET ((CCF-BUG::X CCF-BUG::X-302))
        (VALUES
         (FORMAT NIL "cubed: ~a" (COALTON:COALTON (CCF-BUG::CUBE1 CCF-BUG::X)))))

Which is how I ended up at my example above, (coalton (cube1 (lisp Integer () x))).

I'd like to reiterate, I'm not really poking into this because I need this personally, or even that I think it's broken. There are enough ways to get around this with little hacks, but I just want to clarify behavior so that it can be defined clearly in documentation.

from coalton.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.