* [Caml-list] getting the value of the first expression
@ 2001-10-18 9:44 Rafael 'Dido' Sevilla
2001-10-18 10:00 ` Markus Mottl
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Rafael 'Dido' Sevilla @ 2001-10-18 9:44 UTC (permalink / raw)
To: Caml List
I'm trying to write a simple compiler using Objective Caml, and what I
can say is that it's been a far more pleasant experience than doing the
same thing in C and Yacc, and I've learned a fair bit of the language
this way. However there's one small thing I've wanted to do because
it's needed in my compiler. Say I have a group of functions like this.
emit_parm "ldc" offset;
emit "ind"
The value of this whole expression is the value of the emit application.
What if I want the value of the entire expression to be the value of
the emit_parm application? I can't interchange the order of these two
expressions obviously because the two function applications have side
effects (they generate the assembly language for my virtual machine
architecture) Is there a way to do this? I've been able to work around
my ignorance of the existence of such a feature but I can't help but
feel that there *must* be a better way.
One way I've thought of is to create a reference, but I can't help but
feel that there's another way to do it.
--
Rafael R. Sevilla <sevillar@team.ph.inter.net> +63(2) 8177746 ext. 8311
Programmer, Inter.Net Philippines +63(917) 4458925
http://dido.engr.internet.org.ph/ OpenPGP Key ID: 0x5CDA17D8
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] getting the value of the first expression
2001-10-18 9:44 [Caml-list] getting the value of the first expression Rafael 'Dido' Sevilla
@ 2001-10-18 10:00 ` Markus Mottl
2001-10-18 10:05 ` Dmitry Lomov
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Markus Mottl @ 2001-10-18 10:00 UTC (permalink / raw)
To: Rafael 'Dido' Sevilla; +Cc: Caml List
On Thu, 18 Oct 2001, Rafael 'Dido' Sevilla wrote:
> emit_parm "ldc" offset;
> emit "ind"
If you want to return the result of "emit_parm", just bind it:
let res = emit_parm "ldc" offset in
emit "ind";
res
Regards,
Markus Mottl
--
Markus Mottl markus@oefai.at
Austrian Research Institute
for Artificial Intelligence http://www.oefai.at/~markus
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] getting the value of the first expression
2001-10-18 9:44 [Caml-list] getting the value of the first expression Rafael 'Dido' Sevilla
2001-10-18 10:00 ` Markus Mottl
@ 2001-10-18 10:05 ` Dmitry Lomov
2001-10-18 10:23 ` Bruce Hoult
2001-10-18 12:18 ` Julian Assange
3 siblings, 0 replies; 5+ messages in thread
From: Dmitry Lomov @ 2001-10-18 10:05 UTC (permalink / raw)
To: Rafael 'Dido' Sevilla; +Cc: Caml List
Hi Rafael,
On Thu, 18 Oct 2001, Rafael 'Dido' Sevilla wrote:
> it's needed in my compiler. Say I have a group of functions like this.
>
> emit_parm "ldc" offset;
> emit "ind"
>
> The value of this whole expression is the value of the emit application.
> What if I want the value of the entire expression to be the value of
> the emit_parm application? I can't interchange the order of these two
> expressions obviously because the two function applications have side
> effects (they generate the assembly language for my virtual machine
> architecture) Is there a way to do this? I've been able to work around
> my ignorance of the existence of such a feature but I can't help but
> feel that there *must* be a better way.
The better way is:
let value = emit_parm "ldc" offset in
emit "ind"; value
Dmitry
--
Dmitry Lomov / Lanit-TERCOM Inc.
Phone: +7(812)428-45-24
e-mail: dsl@tepkom.ru
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] getting the value of the first expression
2001-10-18 9:44 [Caml-list] getting the value of the first expression Rafael 'Dido' Sevilla
2001-10-18 10:00 ` Markus Mottl
2001-10-18 10:05 ` Dmitry Lomov
@ 2001-10-18 10:23 ` Bruce Hoult
2001-10-18 12:18 ` Julian Assange
3 siblings, 0 replies; 5+ messages in thread
From: Bruce Hoult @ 2001-10-18 10:23 UTC (permalink / raw)
To: Rafael 'Dido' Sevilla, Caml List
At 5:44 PM +0800 18/10/01, Rafael 'Dido' Sevilla wrote:
>emit_parm "ldc" offset;
>emit "ind"
>
>The value of this whole expression is the value of the emit application.
> What if I want the value of the entire expression to be the value of
>the emit_parm application? I can't interchange the order of these two
>expressions obviously because the two function applications have side
>effects
You just need a variable binding:
let result = emit_parm "ldc" offset in
emit "ind";
result
-- Bruce
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] getting the value of the first expression
2001-10-18 9:44 [Caml-list] getting the value of the first expression Rafael 'Dido' Sevilla
` (2 preceding siblings ...)
2001-10-18 10:23 ` Bruce Hoult
@ 2001-10-18 12:18 ` Julian Assange
3 siblings, 0 replies; 5+ messages in thread
From: Julian Assange @ 2001-10-18 12:18 UTC (permalink / raw)
To: Rafael 'Dido' Sevilla; +Cc: Caml List
> emit_parm "ldc" offset;
> emit "ind"
>
> The value of this whole expression is the value of the emit application.
> What if I want the value of the entire expression to be the value of
> the emit_parm application? I can't interchange the order of these two
let x = emit_parm "ldc" offset
in
emit "ind"; x
--
Julian Assange |If you want to build a ship, don't drum up people
|together to collect wood or assign them tasks and
proff@iq.org |work, but rather teach them to long for the endless
proff@gnu.ai.mit.edu |immensity of the sea. -- Antoine de Saint Exupery
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2001-10-18 13:02 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-18 9:44 [Caml-list] getting the value of the first expression Rafael 'Dido' Sevilla
2001-10-18 10:00 ` Markus Mottl
2001-10-18 10:05 ` Dmitry Lomov
2001-10-18 10:23 ` Bruce Hoult
2001-10-18 12:18 ` Julian Assange
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox