You can use destructuring
user=> (let [[a b] [(+ 1 2) (+ 2 3)]]
[a b])
[3 5]
Christopher Howard writes:
> In Clojure, what is the easiest (cleanest) way to return "multiple"
> values from a function, in order to work with them immediately
> afterwards? In Haskell you can return a tuple
In Clojure, what is the easiest (cleanest) way to return "multiple"
values from a function, in order to work with them immediately
afterwards? In Haskell you can return a tuple, and pattern match the
components into variables.
Prelude> let (a, b) = (1 + 4, 2 - 1)
Prelude> a
5
Prelude> b
1
IIRC, P
On Tue, Jan 3, 2012 at 6:05 PM, meb wrote:
> I see two fairly straightforward paths to simulating multiple returns
> without breaking existing callers. Both take advantage of thread-local
> state and establish one convention for the caller ...
Both of them have reentrancy problems -- in the push-
It seems like we're talking about conflation of language
implementation details to simulate a hash-map. Why not just use a
hash-map for named values? Or a lazy sequence? A function returns a
'value', which can be a single thing, a collection of things, or even
an arbitrary graph of things. If a
I see two fairly straightforward paths to simulating multiple returns
without breaking existing callers. Both take advantage of thread-local
state and establish one convention for the caller: before calling the
function again, every caller interested the extra return values must
ask for these extra
> I think, I'll stop here. You won't convince me that this approach is
> practicable anytime soon. ;-)
I certainly won't try too hard either. I'm not questioning here
whether it is immediately practicable to implement (maybe not, and in
case a very long discussion) but is it potentially useful?
nchurch writes:
> You're quite correct that the namespace \mechanism as it stands would
> not work for thisgood point. I guess I am just suggesting using
> the \syntax to do something let-like. Perhaps it would be better to
> make up a completely different syntax.
>
> As for your example, I
You're quite correct that the namespace \mechanism as it stands would
not work for thisgood point. I guess I am just suggesting using
the \syntax to do something let-like. Perhaps it would be better to
make up a completely different syntax.
As for your example, I'm still not sure we understa
nchurch writes:
> Replying to Tassilo: I'm not quite sure I understand this problem:
>
>> then changing its name requires changing all places where
>> clojure.core.quotient/remainder is used
>
> surely the call to Values takes place inside the function definition,
> which happens \once. If you w
destructureable object. But this
changes the interface: the function no longer directly returns a
singular value. Metadata avoids this problem, but doesn't work on
numbers, among other things. So there really are cases where having
multiple return values would help (when you want a function to
On Mon, Jan 2, 2012 at 2:16 PM, Tassilo Horn wrote:
> nchurch writes:
>
> Hi,
>
>> Someone was asking on the list here about multiple return values,
>> which Clojure does not have.
>>
>> If the facility were ever added, perhaps multiple values could be
&g
nchurch writes:
Hi,
> Someone was asking on the list here about multiple return values,
> which Clojure does not have.
>
> If the facility were ever added, perhaps multiple values could be
> accessed via namespaces. Functions would possess another level of
> namespace and h
Someone was asking on the list here about multiple return values,
which Clojure does not have.
If the facility were ever added, perhaps multiple values could be
accessed via namespaces. Functions would possess another level of
namespace and have the ability to inject values into the environment
On Dec 23, 5:08 am, Alan Malloy wrote:
>
> It turns out even this is not true, becauseproxyuses some kind of
> deep JVM magic called (appropriately)ProxyClasses. So every time you
> write (proxy[Object] (...anything at all...)), you get an instance of
> the same class, initialized with a differe
On Dec 22, 5:48 pm, Brian Goslinga wrote:
> On Dec 22, 8:52 am, Razvan Rotaru wrote:> What do
> you mean by site?
> > For example, how is it when I'm creating my proxy inside a macro? (and
> > assuming this macro is called many times)
>
> > (defmacro [a-class]
> > (proxy (a-class) ))
>
>
On Dec 22, 8:52 am, Razvan Rotaru wrote:
> What do you mean by site?
> For example, how is it when I'm creating my proxy inside a macro? (and
> assuming this macro is called many times)
>
> (defmacro [a-class]
> (proxy (a-class) ))
>
> Razvan
Once all code is macroexpanded, every use of pr
On Dec 14, 5:33 pm, Tom Faulhaber wrote:
> Razvan,
>
> I believe that proxy actually only creates a new class per call site,
> not per instance. However, I can't completely swear to this.
>
> Anyone with more detailed knowledge than I have want to comment?
>
> Assuming I'm right,, you should be fi
Thanks.
On Dec 14, 8:30 pm, Alan Malloy wrote:
> Correct, just like closures and reifies.
>
> On Dec 14, 7:33 am, Tom Faulhaber wrote:
>
>
>
>
>
>
>
> > Razvan,
>
> > I believe that proxy actually only creates a new class per call site,
> > not per instance. However, I can't completely swear to
Correct, just like closures and reifies.
On Dec 14, 7:33 am, Tom Faulhaber wrote:
> Razvan,
>
> I believe that proxy actually only creates a new class per call site,
> not per instance. However, I can't completely swear to this.
>
> Anyone with more detailed knowledge than I have want to comment?
Razvan,
I believe that proxy actually only creates a new class per call site,
not per instance. However, I can't completely swear to this.
Anyone with more detailed knowledge than I have want to comment?
Assuming I'm right,, you should be fine to have lots of instances.
HTH,
Tom
On Dec 13, 10
On Tue, 2011-12-13 at 10:52 -0800, Razvan Rotaru wrote:
> Thanks. I don't know how this hashmap works, but at the first glance
> there seems to be one problem: the two values don't get garbage
> collected at the same time.
There are problems with weak hashmaps, but I wouldn't count that among
them
Thanks. I don't know how this hashmap works, but at the first glance
there seems to be one problem: the two values don't get garbage
collected at the same time. I'll look more into it, thanks.
On Dec 13, 3:10 am, Stephen Compall wrote:
> On Mon, 2011-12-12 at 10:54 -0800, Razvan Rotaru wrote:
> >
I don't want to change the interface i'm exposing to the outer world.
May be that I'm thinking too javaish, but what I miss here is a
possibility to extend the base class. :)
On Dec 12, 9:31 pm, James Reeves wrote:
> On 12 December 2011 18:54, Razvan Rotaru wrote:
>
> > - function returns a valu
Thanks Tom. Using proxy like this could work. But i'm worried about
one thing.What happens if I have many instances? With proxy there's a
new class with each instance. Could I run out of permgen space?
On Dec 13, 9:38 am, Tom Faulhaber wrote:
> Razvan,
>
> I think that you can implement your idea
Razvan,
I think that you can implement your idea of "extending the class with
proxy" in the following way (originally suggested to me by Rich Hickey
& Chris Houser for use with the pretty printer):
(let [extra-fields (ref {:field1 extra-value1, :field2 extra-value2}]
(proxy [Writer IDeref]
On Mon, 2011-12-12 at 10:54 -0800, Razvan Rotaru wrote:
> - function returns a value which is a java instance (not possible to
> change here, or at least not from what I see - it needs to be a java
> instance)
> - i need to be able to call some function which gets some values that
> are not part of
Intuitively it sounds like you are making something much more complicated
than it needs to be. I'd say to return from your computation a vector with
the two values, or possibly a map with them.
If you need to create some kind of Java interop object, then map the result
of the computation to that
On Mon, Dec 12, 2011 at 10:54 AM, Razvan Rotaru wrote:
> Hi,
>
> I read that there's no such thing as lisp-like multiple values return
> in clojure. We can use vectors, and the destructuring feature helps
> also.
>
> However, for what I'm trying to do I need to emulate somehow the
> following beha
On 12 December 2011 18:54, Razvan Rotaru wrote:
> - function returns a value which is a java instance (not possible to
> change here, or at least not from what I see - it needs to be a java
> instance)
Why does it need to be a Java instance?
- James
--
You received this message because you are
Hi,
I read that there's no such thing as lisp-like multiple values return
in clojure. We can use vectors, and the destructuring feature helps
also.
However, for what I'm trying to do I need to emulate somehow the
following behavior:
- function returns a value which is a java instance (not possibl
On Tue, Oct 21, 2008 at 7:48 AM, Jeffrey Chu <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> If you really need multiple value calls, you can always try to emulate
> parts of it with some fancy macros. I've hacked up a quick proof of
> concept - I haven't gotten a chance to test it too much, but it seems
>
0, 1:00 pm, "Fredrik Appelberg" <[EMAIL PROTECTED]>
wrote:
> On Mon, Oct 20, 2008 at 1:03 PM, Parth Malwankar
> <[EMAIL PROTECTED]>wrote:
>
>
>
>
>
> > On Oct 20, 3:51 pm, "Fredrik Appelberg" <[EMAIL PROTECTED]>
> > wrote:
> > &g
On Mon, Oct 20, 2008 at 1:03 PM, Parth Malwankar
<[EMAIL PROTECTED]>wrote:
>
> On Oct 20, 3:51 pm, "Fredrik Appelberg" <[EMAIL PROTECTED]>
> wrote:
> > Hi all,
> >
> > The CL feature for handling multiple return values from a function come
> in
On Oct 20, 7:03 am, Parth Malwankar <[EMAIL PROTECTED]> wrote:
> On Oct 20, 3:51 pm, "Fredrik Appelberg" <[EMAIL PROTECTED]>
> wrote:
>
> > Hi all,
>
> > The CL feature for handling multiple return values from a function come in
> > really ha
On Oct 20, 3:51 pm, "Fredrik Appelberg" <[EMAIL PROTECTED]>
wrote:
> Hi all,
>
> The CL feature for handling multiple return values from a function come in
> really handy sometimes and make for cleaner APIs. For example, the ROUND
> function returns the integer
Hi all,
The CL feature for handling multiple return values from a function come in
really handy sometimes and make for cleaner APIs. For example, the ROUND
function returns the integer part of a float as the regular value (as this
is what you want most of the time), but optionally also returns
36 matches
Mail list logo