Comments (7)
That is the expected behavior.
Also you don't need call-coalton-function
when calling a top-level coalton function.
from coalton.
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.
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.
Regarding your last sentence, yes please do make a separate issue.
from coalton.
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.
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.
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)
- FSET has compilation errors while loading Coalton via Quicklisp HOT 3
- Coalton floating-point numerics are not at performance parity with Lisp HOT 1
- Review built-in types in the default type environment
- Review src/package.lisp for correctness of comments
- `tree:insert` results in a red branch, where it should result in a black branch like `tree:insert-or-replace` HOT 1
- consider changing FSET for SYCAMORE
- docs/defpackages mention now-nonexistent `double/`, `single/`
- constant fold `fromInt` on literals
- Revisit keyword-function alists in `coalton-impl/codegen/transformations:traverse`
- random unicode characters in source
- Remove `traverse` `action`s' explicit function reference passing HOT 1
- TRANSLATE-EXPRESSION on NODE-FOR is buggy HOT 4
- into-iter bug
- for sometimes causes a runtime type error
- add tests for all core language looping constructs
- Inliner doesn't work with `return` HOT 1
- `:coalton/benchmark` deprecated/impendingly deprecated HOT 1
- Improve presentation of low-level reader errors
- Type error on over-application of anonymous functions
- Coalton package form: support "shadow" clause
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from coalton.