Home > Archive > Functional > August 2007 > Newbie Question: Is it allowed for the function to change the value of parameters?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Newbie Question: Is it allowed for the function to change the value of parameters?
|
|
| beginner 2007-07-24, 7:08 pm |
| Hi,
I am really new to functional programming. I am just wondering if it
is theoretically allowed to for the function to change the value of
the parameters?
Haskell's list seems to be immutable so it is not a problem. What if I
use python:
def f(list):
list.append("a")
will change the list passed in. Is this generally acceptable practice
in functional programming?
How about this:
list=[]
f= lambda x: list.append(x)
Now I just defined a function that has side effects?
Thanks,
cg
| |
| beginner 2007-07-24, 10:05 pm |
| On Jul 24, 1:07 pm, Dan Bensen <randomg...@cyberspace.net> wrote:
> beginner wrote:
>
> No, not in pure functional programming. In pure FP, you're not supposed
> to change any variable values once you bind them.
>
>
> In pure FP, your function should return list + ["a"].
> That would be functional, because it creates a new value without
> changing the old ones.
>
>
> Same thing. That has a side effect, so it's not pure FP.
>
> --
> Danwww.prairienet.org/~dsb/
Thanks for the response. It clears up a big question for me.
Then I guess it is pretty difficult to go pure FP in python, because
it will involve copying lists for many times.
| |
| Paul Rubin 2007-07-25, 4:18 am |
| beginner <zyzhu2000@gmail.com> writes:
> Then I guess it is pretty difficult to go pure FP in python, because
> it will involve copying lists for many times.
You can sometimes approach a functional style by using generators
instead of lists, so instead of appending lists you would chain the
generators. Functional programming sometimes uses other special data
structures to avoid a lot of copying as well. For example, instead of
mutable dictionaries, a functional program might use balanced tree
structures, so given a tree, making a new tree with some node changed
would involve O(n) operations making new nodes (the new tree would
share the rest of its structure with the old tree, and of course the
old, replaced nodes would be garbage collected if the old tree was no
longer referenced). Haskell's Data.Map module works like that, and
Hemlock Lisp has AVL trees with a Python-like dictionary interface.
For more info, see Chris Okasaki's excellent book "Purely Functional
Data Structures". He also has some online papers on the subject.
| |
| rossberg@ps.uni-sb.de 2007-07-25, 4:18 am |
| On 25 Jul., 05:21, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
> so given a [balanced] tree, making a new tree with some node changed
> would involve O(n) operations making new nodes
You certainly mean O(log n), assuming that n is the number of nodes in
the tree.
- Andreas
| |
| Paul Rubin 2007-07-25, 7:07 pm |
| rossberg@ps.uni-sb.de writes:
> On 25 Jul., 05:21, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
>
> You certainly mean O(log n), assuming that n is the number of nodes in
> the tree.
Yes, clearly so, not sure what happened there. Thanks.
| |
| Ulf Wiger 2007-07-27, 8:05 am |
| >>>>> "JD" == Joachim Durchholz <jo@durchholz.org> writes:
JD> These things don't go well with side effects - if you construct
JD> a function and pass it around, you lose a great deal of control
JD> when it will be evaluated, and that means you can't easily
JD> control the order in which the side effects will happen. So many
JD> FPLs indeed try to restrict or control side effects (Haskell,
JD> Clean), others rely on "common sense" and simply make
JD> side-effect-free programming easy (OCaml, SML, some
JD> styles/schools of Lisp programming).
There are places where higher order functions and side effects
go well together (these fall into the latter category, where the
programmer must exercise caution.
The Erlang-based distributed real-time dbms, Mnesia, uses
function objects to encapsulate database transactions, e.g.
F = fun() ->
[P] = mnesia:read({person, X}),
P1 = update_salary(P, 1000),
mnesia:write(P1)
end,
mnesia:transaction(F).
The side effects inside the closure should be under Mnesia's
control, i.e. you should use only API functions meant for
transactions. If you do, Mnesia can use distributed deadlock
prevention, and restart the transaction when needed.
Very useful, but the programmer is strongly cautioned against
introducing other kinds of side effect. In practice, this
works out well.
Another example: I once wrote a virtual channel manager
intended for communication between heterogeneous systems.
The novel feature was that it had version negotiation and
supported automatic chaining of data conversion functions
to allow communication between different versions of the
same software (within limits.) These funs were of course
side-effect free.
Another use of funs was to hide the details of the
communication mechanism. When setting up a channel,
you instrumented it with specific behaviour, e.g.
{on_receive,
fun(ChNo, SendF, {To,{From,Msg}} = What) ->
To ! {ChNo, fun(Reply) ->
SendF(From, {To,Reply})
end, Msg}
(which meant that the on_receive handler would pass
on the message, along with the fun to use if the
receiver wanted to reply to the sender.)
A server could then handle messages in this fashion:
rex_loop(Channel) ->
receive
{ChNo, ReplyF, ping} when is_integer(ChNo),
is_function(ReplyF,1) ->
ReplyF(pong),
rex_loop(Channel)
end.
The same server could then easily be called on using
normal Erlang messages:
Rex ! {0, fun(M) -> Me ! {reply, M} end, ping}.
Obviously, nothing stops an evil program from sending
a fun(_) -> exit(suicide) end. Again, programmer
cooperation is required.
Not that any of this refutes your argument. Higher-order
functions can be extremely useful together with side-effects,
but mainly as long as you are willing to give up a lot of
that compile-time safety. Erlang falls squarely into your
"common sense" category. (:
As a general rule, this type of programming is evil and
should be used as sparingly as possible.
BR,
Ulf W
--
Ulf Wiger, Senior Specialist,
/ / / Architecture & Design of Carrier-Class Software
/ / / Team Leader, Software Characteristics
/ / / Ericsson AB, IMS Gateways
| |
| Jon Harrop 2007-07-27, 7:06 pm |
| Ulf Wiger wrote:
> As a general rule, this type of programming is evil and
> should be used as sparingly as possible.
Ironically, a Hindley-Milner type checker is one of the few programs where
mutable refs work very well in an otherwise functional setting. :-)
--
Dr Jon D Harrop, Flying Frog Consultancy
OCaml for Scientists
http://www.ffconsultancy.com/produc...entists/?usenet
| |
| Rainer Joswig 2007-07-31, 10:07 pm |
| In article <n0bqdsg1wp.fsf@hod.lan.m-e-leypold.de>,
development-2006-8ecbb5cc8aREMOVETHIS@ANDTHATm-e-leypold.de (Markus
E.L.) wrote:
>
>
> According to some Lispers (Rainer Joswig?) Lisp is a "multi paradigm
> language".
http://en.wikipedia.org/wiki/LISP
"Paradigm: multi-paradigm: functional, procedural, object-oriented"
Above is true for Common Lisp. R5RS Scheme is only functional and
procedural. Neither Scheme nor Common Lisp are purely functional.
>
>
>
> No. Contrary to popular belief, the IO Monad in, e.g., Haskell
> does not have side effects. :-).
>
> Regards -- Markus
--
http://lispm.dyndns.org
| |
| Jon Harrop 2007-07-31, 10:07 pm |
| Markus E.L. wrote:
>
> According to some Lispers (Rainer Joswig?) Lisp is a "multi paradigm
> language".
Lisp is both functional (it supports first-class lexical closures) and
multi-paradigm. Although it is one of the least pure FPLs.
--
Dr Jon D Harrop, Flying Frog Consultancy
OCaml for Scientists
http://www.ffconsultancy.com/produc...entists/?usenet
| |
| Rainer Joswig 2007-08-01, 8:05 am |
| In article <f8pq4r$5ev$1@online.de>,
Joachim Durchholz <jo@durchholz.org> wrote:
> Rainer Joswig schrieb:
>
> I think established terminology is slightly misleading here.
>
> It's not "purely functional" languages, it's languages that are both
> pure and functional. Being pure (i.e. not having side effects) and being
> functional (using functions as ordinary values, passing and constructing
> them) are orthogonal concecpts, and I suspect they can even exist
> independently of each other.
I agree with that.
> It's just that pureness happened to be explored more for functional
> languages than for others, so pureness somehow got associated with being
> functional. (I imagine that dataflow or logical languages can be pure
> without being functional.)
But the combination of 'without side effects'
and 'functional' forms a useful class of programming languages.
I find the wording useful.
More important: a language like SML enforces you
to use the Functional Programming paradigm (note, that
is nothing bad, just a neutral description). FP
is the single most important programming style for SML.
In Common Lisp the use of FP style programming is not 'enforced',
just 'supported'.
>
> Regards,
> Jo
--
http://lispm.dyndns.org
| |
| Rainer Joswig 2007-08-01, 7:08 pm |
| In article <f8pvfj$6kl$1@news.xmission.com>,
Thant Tessman <adm@standarddeviance.com> wrote:
> Rainer Joswig wrote:
>
> [...]
>
>
> FP is the most natural way to program in SML, but it isn't "enforced."
Can I use SML without using FP? Can I use its standard
library without FP? Maybe you care to explain
a bit?
Btw., is it true that there is no language definition of
SML online? I see references to the book
'The Definition of Standard ML (Revised)', but
no language reference/definition online. I see
references for the base library, too.
But really no language reference?
>
> [...]
>
> -thant (another ex-Scheme programmer who switched to SML)
--
http://lispm.dyndns.org
| |
| Rainer Joswig 2007-08-01, 7:08 pm |
| In article <f8qatl$pbg$1@online.de>,
Joachim Durchholz <jo@durchholz.org> wrote:
> Rainer Joswig schrieb:
>
> I agree with that, it's just that it's misleading for those who don't
> already know the terminology.
>
>
> The value questions, then, would be:
> 1) What additional paradigms are supported?
> 2) What's the worth of these additional paradigms?
>
> Most FPers tend to disagree that the additional paradigms are worth much.
Probably that's a self-selected group. They chose FPLs because
they like the paradigm. Ask Prolog developers and they will
tell you that programming with logic is all you need
(which is also true ;-) ).
Ask Lisp programmers and they will tell you that they
like to choose.
Common Lisp supports imperative, procedural programming.
(Personally I think simple (!) functional programming with side
effects is not that far from that.) Old-style loops and
other control constructs (including goto). I'm not religiously
connected to that. I comes handy sometimes. Sometimes
it gets overused.
Common Lisp also supports object-oriented programming
in a style that is somewhat integrated with functional
programming. Message Passing has been replaced with
Generic Functions.
I'd say for many (though not all) Lisp developers, OOP is highly
popular in Common Lisp. Many libraries are written
in some OO-style using the provided language constructs.
Parts of the language are written
using OO - also where the standard does not say anything.
I/O using streams is written that way in most
implementations (Gray streams, simple streams),
the exception system is written that
way in most implementations, the OO system itself
is written that way in most implementations.
Same for GUI libs and development environments.
OCAML also integrates some kind of OO. Just from
following some of the discussions I get the impression
that the O in OCAML is not that popular. Just an
impression. OCAML users may correct me.
For some group of users these are just the basic
paradigms that happen to be supported out of the box.
Quite a few other paradigms are supported by
implementations and libraries. It is always
important that these integrate nicely and that's
why Common Lisp has some of its features.
Widely supported (examples):
* Programming with Predicate Logic
* Rule-based programming
* Programming with Relations
* Frames
* Description Logics
* Distributed Object-Oriented Programming (via CORBA)
* Graphical Notations
* Semantic Networks
* Fuzzy logic
* Genetic Programming
> Some will even go so far as to say that they don't have any value
> whatsoever - I wouldn't go that far, but I think their value tends to
> get exaggerated simply because people are used to having them and
> haven't explored the functional alternatives well enough to have the
> data for a fair comparison.
> For example, people often think that the imperative (procedural)
> paradigm is necessary for efficiency and for interacting with the
> outside world. However, both the efficiency theory and the outside
> interaction theory have been refuted (by demonstration, the former by
> OCaml, the latter by Haskell's IO subsystem).
>
>
> Agreed.
>
> Regards,
> Jo
--
http://lispm.dyndns.org
| |
| Rainer Joswig 2007-08-01, 7:08 pm |
| In article <f8qfks$vmv$1@online.de>,
Joachim Durchholz <jo@durchholz.org> wrote:
>
> From the perspective of a Haskeller, that's entirely superfluous.
> (Simon Peyton-Jones: "Haskell - the World's Finest Imperative Language."
> He is serious about that claim, and has evidence to back that up.)
Guy Lewis Steele, Jr. and Gerald Jay Sussman.
"Lambda: The Ultimate Imperative". MIT AI Lab.
AI Lab Memo AIM-353. March 1976
http://library.readscheme.org/page1.html
....
> Most FPLs seem to be underrepresented here. (Library support at best,
> and possibly an area where some syntactic sugar could be required to
> make it smooth.)
>
>
> Should be easy. (Unless I'm missing something.)
http://ap5.com/doc/ap5-frame.html
>
>
> Not sure what that is.
"Description logics are knowledge representation languages tailored
for expressing knowledge about concepts and concept hierarchies."
http://dl.kr.org/
>
> Not sure what specific advantages Lisp would have here.
> Also not sure what the advantages of a graphical notation would be. I
> found most that I have seen too wasteful of screen space to be very
> useful (though I haven't seen much).
Used for example in Music composition:
http://recherche.ircam.fr/equipes/repmus/OpenMusic/
Some screenshots there.
OpenMusic allows you to draw algorithms and run them.
It provides a graphical notation for a bit of Lisp.
>
>
> Don't know.
>
>
> That would be a bunch of operators. HOFs if you want to express an
> algorithms for different kinds of fuzziness models at once.
>
>
> Just a library in any language, unless I'm missing something.
Many paradigms can be implemented as a library. If the
language is flexible enough it may integrate nicely. In the
case of Generic Programming, it maps nicely into Lisp,
since one has already a data representation for Lisp
programs that can be readily used.
>
> Regards,
> Jo
--
http://lispm.dyndns.org
| |
| Donn Cave 2007-08-01, 7:08 pm |
| NNTP-Posting-Host: xceed.cac.washington.edu
X-Trace: gnus01.u.washington.edu 1186000049 21927 128.95.135.150 (1 Aug 2007 20:27:29 GMT)
X-Complaints-To: help@cac.washington.edu
NNTP-Posting-Date: Wed, 1 Aug 2007 20:27:29 +0000 (UTC)
User-Agent: MT-NewsWatcher/3.4 (PPC Mac OS X)
Bytes: 2924
Xref: number1.nntp.dca.giganews.com comp.lang.functional:62797
In article <46b0d055$0$31220$426a74cc@news.free.fr>,
Bruno Desthuilliers <bdesth.quelquechose@free.quelquepart.fr> wrote:
> Markus E.L. a écrit :
> (snip)
>
>
> No one to answer on this ?-)
Well, my answer would be something like `if you have to ask,
then it isn't a functional programming language.' In the
useful sense of the word, it's a matter of emphasis, not
presence or absence of a set of features.
Haskell is a functional programming language if there ever
was one, and it would continue to be, if keyboards lost their
backslash key and no one could use the Haskell lambda. Python
has lambda, but to look at that construct and its issues only
confirms that it is not a functional programming language
(not the scope issue, which has indeed changed -- I'm thinking
of all the things that are excluded because they're "statements".)
> I admit I didn't go that far with Haskell, so I may be wrong, but I
> don't get how IO could be totally side-effect free. But it probably
> depends on the definition of 'side-effects'
Yes, I bet it does! The IO monad is a very interesting construct.
No reading recommendations, but there's http://www.haskell.org/
I'm quite ignorant of mathematics myself, and don't generally
notice that to be a huge obstacle. Not saying there's no benefit,
just that the main requirement seems to be elasticity of mind
and a strong tolerance for abstraction (i.e., these are the things
I find myself wishing for.)
Donn Cave, donn@u.washington.edu
| |
| George Neuner 2007-08-01, 7:08 pm |
| On Wed, 01 Aug 2007 13:18:08 +0200, Joachim Durchholz
<jo@durchholz.org> wrote:
>Rainer Joswig schrieb:
>
>I think established terminology is slightly misleading here.
>
>It's not "purely functional" languages, it's languages that are both
>pure and functional. Being pure (i.e. not having side effects) and being
>functional (using functions as ordinary values, passing and constructing
>them) are orthogonal concecpts, and I suspect they can even exist
>independently of each other.
>It's just that pureness happened to be explored more for functional
>languages than for others, so pureness somehow got associated with being
>functional. (I imagine that dataflow or logical languages can be pure
>without being functional.)
It's just the imprecise nature of English. As a native speaker, I
interpret Rainer's last sentence as a comparison to some other
(unnamed) languages which only support programming in functional
style.
George
--
for email reply remove "/" from address
| |
| Rainer Joswig 2007-08-01, 7:08 pm |
| In article <c4t1b3tvcj0v2ggpkeoc07cu7dttqhnhc5@4ax.com>,
George Neuner <gneuner2/@comcast.net> wrote:
> On Wed, 01 Aug 2007 13:18:08 +0200, Joachim Durchholz
> <jo@durchholz.org> wrote:
>
>
> It's just the imprecise nature of English. As a native speaker, I
> interpret Rainer's last sentence as a comparison to some other
> (unnamed) languages which only support programming in functional
> style.
>
> George
> --
> for email reply remove "/" from address
;-)
But I meant (old c.l.f FAQ):
" 3.1. Purity
What is a "purely functional" programming language?
This question has been the subject of some debate in the functional
programming community. It is widely agreed that languages such as
Haskell and Miranda are "purely functional", while SML and Scheme
are not. However, there are some small differences of opinion
about the precise technical motivation for this distinction.
One definition that has been suggested is as follows:
The term "purely functional" is often used to describe
languages that perform all their computations via function
application. This is in contrast to languages, such as Scheme
and Standard ML, that are predominantly functional but also
allow `side effects' (computational effects caused by
expression evaluation that persist after the evaluation
is completed).
Sometimes, the term "purely functional" is also used in
a broader sense to mean languages that might incorporate
computational effects, but without altering the notion of
`function' (as evidenced by the fact that the essential
properties of functions are preserved.) Typically, the
evaluation of an expression can yield a `task', which is
then executed separately to cause computational effects.
The evaluation and execution phases are separated in such
a way that the evaluation phase does not compromise
the standard properties of expressions and functions.
The input/output mechanisms of Haskell, for example, are
of this kind.
"
--
http://lispm.dyndns.org
| |
| George Neuner 2007-08-01, 7:08 pm |
| On Wed, 01 Aug 2007 23:38:01 +0200, Rainer Joswig <joswig@lisp.de>
wrote:
>In article <c4t1b3tvcj0v2ggpkeoc07cu7dttqhnhc5@4ax.com>,
> George Neuner <gneuner2/@comcast.net> wrote:
>
>
>But I meant (old c.l.f FAQ):
> :
That's what I said ... imprecise! 8-)
http://thesaurus.reference.com/browse/purely
In English, "purely" is a synonym for "only".
Technical discussions of any kind are problematic in English because
English words can have many meanings. It doesn't help when the
discussion involves different disciplines which assign different
technical meanings to the same word in addition to its lay meaning(s).
Probably we should conduct technical discussions in Sanskrit.
George
--
for email reply remove "/" from address
| |
| Ingo Menger 2007-08-02, 4:28 am |
| On 1 Aug., 20:25, Bruno Desthuilliers
<bdesth.quelquech...@free.quelquepart.fr> wrote:
> Markus E.L. a =E9crit :>>Joachim Durchholz a =E9crit :
>
>
> (snip)
>
>
>
> No one to answer on this ?-)
How about : When the conclusion is absurd, check your premises.
| |
|
|
| Jon Harrop 2007-08-02, 8:06 am |
| Rainer Joswig wrote:
> Common Lisp also supports object-oriented programming
Is CLOS bundled with CL?
> OCAML also integrates some kind of OO. Just from
> following some of the discussions I get the impression
> that the O in OCAML is not that popular. Just an
> impression. OCAML users may correct me.
Objects are rarely used in OCaml, yes.
> Widely supported (examples):
>
> * Programming with Predicate Logic
> * Rule-based programming
> * Programming with Relations
> * Frames
> * Description Logics
> * Distributed Object-Oriented Programming (via CORBA)
> * Graphical Notations
> * Semantic Networks
> * Fuzzy logic
> * Genetic Programming
This is a very nice list of paradigms supported in many languages but
perhaps it is misleading to claim that something like "graphical notation"
is "widely supported in Lisp". Mathematica provides extensive support for
graphical notation in the language, bundling an IDE with typesetting and
real-time hardware accelerated interactive rendering. OCaml and BBC BASIC
bundle minimal graphics functionality, allowing you to draw dots, lines and
triangles. Common Lisp bundles absolutely nothing AFAIK, not even a
standard library that can draw a dot on a pixmap. Is that right?
--
Dr Jon D Harrop, Flying Frog Consultancy
OCaml for Scientists
http://www.ffconsultancy.com/produc...entists/?usenet
| |
| rossberg@ps.uni-sb.de 2007-08-02, 8:06 am |
| On 2 Aug., 12:48, Jon Harrop <j...@ffconsultancy.com> wrote:
> Rainer Joswig wrote:
You have references, arrays, loops, imperative I/O, etc.
[color=darkred]
> Yes: Just write only 0th order functions and avoid closures.
I think you mean 1st order functions. 0th order would be functions
without any arguments, i.e. constants.
- Andreas
| |
| Rainer Joswig 2007-08-02, 8:06 am |
| In article <46b1bac9$0$1626$ed2619ec@ptn-nntp-reader02.plus.net>,
Jon Harrop <jon@ffconsultancy.com> wrote:
> Rainer Joswig wrote:
>
> Is CLOS bundled with CL?
'bundled' is maybe the wrong word. CLOS is a part of CL.
http://www.lispworks.com/documentat...ec/Body/07_.htm
>
>
> Objects are rarely used in OCaml, yes.
>
>
> This is a very nice list of paradigms supported in many languages but
> perhaps it is misleading to claim that something like "graphical notation"
> is "widely supported in Lisp".
The context is 'programming paradigms'.
http://en.wikipedia.org/wiki/Programming_paradigm
This special field is called 'Visual programming languages'.
Graphical notations for programs have been widely
used. I was not talking about typesetting or rendering of diagrams.
OpenMusic is such an example. There you can draw the musical
algorithms and execute those visual programs. 'OpenMusic is a
multiple-dispatch, generic-function based visual object
programming language.' It is a functional language
with a graphical notation.
This paper explains the visual programming language used
for OpenMusic and its relationship to Lisp:
http://recherche.ircam.fr/equipes/r...a/OMICMC98.html
Another visual language written in Lisp for music
compostion is PWGL:
http://www2.siba.fi/pwgl/pwgl.html
> Mathematica provides extensive support for
> graphical notation in the language, bundling an IDE with typesetting and
> real-time hardware accelerated interactive rendering.
The OpenMusic example should make that clear what was meant.
> OCaml and BBC BASIC
> bundle minimal graphics functionality, allowing you to draw dots, lines and
> triangles. Common Lisp bundles absolutely nothing AFAIK, not even a
> standard library that can draw a dot on a pixmap. Is that right?
That's wrong. You can draw dots in Lisp. Plus quite a bit more.
--
http://lispm.dyndns.org
| |
| Rainer Joswig 2007-08-02, 7:09 pm |
| In article <1186054279.182259.119650@o61g2000hsh.googlegroups.com>,
rossberg@ps.uni-sb.de wrote:
> On 2 Aug., 12:48, Jon Harrop <j...@ffconsultancy.com> wrote:
>
> You have references, arrays, loops, imperative I/O, etc.
But you would write a function on the top?
>
>
> I think you mean 1st order functions. 0th order would be functions
> without any arguments, i.e. constants.
>
> - Andreas
--
http://lispm.dyndns.org
| |
| Jon Harrop 2007-08-02, 7:09 pm |
| rossberg@ps.uni-sb.de wrote:
> I think you mean 1st order functions. 0th order would be functions
> without any arguments, i.e. constants.
I was using C-style indexing. ;-)
--
Dr Jon D Harrop, Flying Frog Consultancy
OCaml for Scientists
http://www.ffconsultancy.com/produc...entists/?usenet
| |
| Jon Harrop 2007-08-02, 7:09 pm |
| Rainer Joswig wrote:
> In article <46b1bac9$0$1626$ed2619ec@ptn-nntp-reader02.plus.net>,
> Jon Harrop <jon@ffconsultancy.com> wrote:
>
> 'bundled' is maybe the wrong word. CLOS is a part of CL.
> http://www.lispworks.com/documentat...ec/Body/07_.htm
I didn't know that.
> This special field is called 'Visual programming languages'.
> Graphical notations for programs have been widely
> used. I was not talking about typesetting or rendering of diagrams.
I can't see a difference between Open Music and Mathematica in this context.
> OpenMusic is such an example. There you can draw the musical
> algorithms and execute those visual programs. 'OpenMusic is a
> multiple-dispatch, generic-function based visual object
> programming language.' It is a functional language
> with a graphical notation.
Is that not equally true of Mathematica?
> The OpenMusic example should make that clear what was meant.
I think your example is of an application written in Lisp that not only
provides a GUI to facilitate programming but also exposes Lisp itself. This
approach is certainly not common in other languages.
> That's wrong. You can draw dots in Lisp. Plus quite a bit more.
Ok. I can't find anything on HyperSpec about graphics. Where is the graphics
part of the Common Lisp standard library?
--
Dr Jon D Harrop, Flying Frog Consultancy
OCaml for Scientists
http://www.ffconsultancy.com/produc...entists/?usenet
| |
| rossberg@ps.uni-sb.de 2007-08-02, 7:09 pm |
| On 2 Aug., 16:48, Rainer Joswig <jos...@lisp.de> wrote:
> rossb...@ps.uni-sb.de wrote:
>
>
> But you would write a function on the top?
Sorry, not sure I understand your question, can you rephrase it?
- Andreas
| |
| Rainer Joswig 2007-08-02, 7:09 pm |
| In article <46b21d53$0$1608$ed2619ec@ptn-nntp-reader02.plus.net>,
Jon Harrop <jon@ffconsultancy.com> wrote:
> Rainer Joswig wrote:
>
> I didn't know that.
Hmm, what else can be explained to you and how to bring you up to
speed?
>
> I can't see a difference between Open Music and Mathematica in this context.
Last I looked Mathematica was not a visual programming language.
I was still typing text to enter code.
It has parts of it with it's interactive interface elements.
Just look at the OpenMusic paper I referenced.
>
> Is that not equally true of Mathematica?
How do you represent functions, function calls, loops, data, etc. in
Mathematica? Do you draw boxes, lines and so on to program?
You can create fancy notebook interfaces, but the programming
is still done in a textual language (though nicely displayed).
>
> I think your example is of an application written in Lisp that not only
> provides a GUI to facilitate programming but also exposes Lisp itself. This
> approach is certainly not common in other languages.
Can't say, but there are many interesting visual programming systems.
>
> Ok. I can't find anything on HyperSpec about graphics. Where is the graphics
> part of the Common Lisp standard library?
Use CLX:
http://www.cliki.net/CLX
http://www.stud.uni-karlsruhe.de/~u...xman/index.html
Pixmaps are here:
http://www.stud.uni-karlsruhe.de/~u..._8_Pixmaps.html
Drawing dots is here:
http://www.stud.uni-karlsruhe.de/~u...ing_Points.html
CLX is an interface to X11 that has been developed without
interfacing the C lib.
If you want some thing more highlevel you can use CLIM
(Common Lisp Interface Manager).
Here are some X interfaces:
http://www.cliki.net/Graphics%20Toolkit
Some graphics libraries
http://www.cliki.net/graphics%20library
--
http://lispm.dyndns.org
| |
| Rainer Joswig 2007-08-02, 7:09 pm |
| In article <1186078931.411356.64290@q3g2000prf.googlegroups.com>,
rossberg@ps.uni-sb.de wrote:
> On 2 Aug., 16:48, Rainer Joswig <jos...@lisp.de> wrote:
>
> Sorry, not sure I understand your question, can you rephrase it?
>
> - Andreas
In Lisp I have imperative constructs, so that I don't need
to write one function. I don't even have to write
0th, 1th or nth order functions for my program at all.
Additional to functional constructs, there is
a complete set of non-functional control flow
constructs (including goto). So, to write code
I would not need to write a single function or
use a single LET binding.
Let's make a simple example. How would a non-functional
version of FAC look like?
This would be a completely imperative FAC:
(defparameter *n* 20)
(defparameter *result* 1)
(tagbody
start
(when (zerop *n*) (go end))
(setf *result* (* *n* *result*))
(decf *n*)
(go start)
end))
(print *result*)
--
http://lispm.dyndns.org
| |
| Jon Harrop 2007-08-02, 7:09 pm |
| Rainer Joswig wrote:
> In article <46b21d53$0$1608$ed2619ec@ptn-nntp-reader02.plus.net>,
> Jon Harrop <jon@ffconsultancy.com> wrote:
>
> How do you represent functions, function calls, loops, data, etc. in
> Mathematica? Do you draw boxes, lines and so on to program?
> You can create fancy notebook interfaces, but the programming
> is still done in a textual language (though nicely displayed).
Programs can be laid out graphically via typesetting. Graphical entry of
programs is accomplished using "palettes":
http://www.indiana.edu/~statmath/ma...ted/palette.gif
Moreover, Mathematica's typesetter is extensible and you can add new
programming constructs and define graphical forms for them.
I assume Open Music is not capable of this kind of visual programming?
>
> Use CLX:
> ...
> Here are some X interfaces:
> ...
These don't seem to be bundled with Common Lisp in the standard library.
--
Dr Jon D Harrop, Flying Frog Consultancy
OCaml for Scientists
http://www.ffconsultancy.com/produc...entists/?usenet
| |
| Rainer Joswig 2007-08-02, 7:09 pm |
| In article <2bvebxob99.fsf@hod.lan.m-e-leypold.de>,
development-2006-8ecbb5cc8aREMOVETHIS@ANDTHATm-e-leypold.de (Markus
E.L. 2) wrote:
> Rainer Joswig wrote:
>
>
>
>
> OCaml:
>
> (* Library *)
>
> let goto p = p ();;
>
> (* Imperative FAC *)
>
> let n = ref 20;;
> let result = ref 1;;
>
>
> let rec
>
> start () =
>
> if (!n) = 0 then (goto stop)
> else
> (
> result := !result * !n;
> n := !n - 1;
> goto start
> )
>
> and stop () = () in start ()
> ;;
>
> print_int !result;;
>
>
> The rest of the syntax could be fixed by a campl4 macro in the obvious
> way, but I don't think there is any value in supporting unstructured
> programming (and that is what we're talking about; "unstructured
> programming" as opposed to "structured programming" which latter is
> the use of block control structures like 'if-then-else' and
> 'for-while'
>
> If while-loops are allowed in this little challenge (this is still
> imperative):
>
> let n = ref 20;;
> let result = ref 1;;
>
> while !n>0 do
> result := !result * !n;
> n := !n - 1;
> done
> ;;
>
> print_int !result;;
>
> (also OCaml).
>
> -- Markus
Try without let rec. What you show is emulation
of imperative programming with functional constructs.
--
http://lispm.dyndns.org
| |
|
|
| Rainer Joswig 2007-08-02, 7:09 pm |
| In article <f8tjnr$q2r$1@news.xmission.com>,
Thant Tessman <adm@standarddeviance.com> wrote:
> Rainer Joswig wrote:
>
>
> If it compiles into a goto, is it still merely an "emulation"?
Please.
>
> -thant
--
http://lispm.dyndns.org
| |
| Paul Rubin 2007-08-02, 7:09 pm |
| development-2006-8ecbb5cc8aREMOVETHIS@ANDTHATm-e-leypold.de (Markus E.L. 2) writes:
> Rainer Joswig wrote: > > This would be a completely imperative FAC:
> [Marcus wrote]: > OCaml:
> (* Library *)
> let goto p = p ();; ...
Someone needs to update
http://www.willamette.edu/~fruehr/h.../evolution.html
to compute imperative factorial in CPS style using the continuation
and state monads.
| |
| Rainer Joswig 2007-08-02, 7:09 pm |
| In article <7x3az1y4wa.fsf@ruckus.brouhaha.com>,
Paul Rubin <http://phr.cx@NOSPAM.invalid> wrote:
> development-2006-8ecbb5cc8aREMOVETHIS@ANDTHATm-e-leypold.de (Markus E.L. 2) writes:
>
> Someone needs to update
>
> http://www.willamette.edu/~fruehr/h.../evolution.html
>
> to compute imperative factorial in CPS style using the continuation
> and state monads.
Using monads is functional programming or not? If
you need monads for imperative style programming, I'd
say the language enforces functional programming constructs.
--
http://lispm.dyndns.org
| |
| Jon Harrop 2007-08-02, 7:09 pm |
| Rainer Joswig wrote:
>
> In Lisp I have imperative constructs, so that I don't need
> to write one function. I don't even have to write
> 0th, 1th or nth order functions for my program at all.
> Additional to functional constructs, there is
> a complete set of non-functional control flow
> constructs (including goto). So, to write code
> I would not need to write a single function or
> use a single LET binding.
This is not consistent with my understanding of the term "functional
programming".
> (defparameter *n* 20)
> (defparameter *result* 1)
>
> (tagbody
> start
> (when (zerop *n*) (go end))
> (setf *result* (* *n* *result*))
> (decf *n*)
> (go start)
> end))
>
> (print *result*)
Computing 5! with no functions in SML:
- val n = ref 5;
val n = ref 5 : int ref
- val result = ref 1;
val result = ref 1 : int ref
- while !n > 0 do (result := !n * !result; n := !n - 1);
val it = () : unit
- !result;
val it = 120 : int
However, this C implementation:
int factorial(int n) { return n==0 ? 1 : n*factorial(n-1); }
does not constitute "functional programming" as you imply. Nor are "let
bindings" specific to functional programming. Nor does Lisp provide
a "complete set of non-functional control flow constructs", the most
obvious omission being pattern matching. Finally, this is all swinging on
an ill-specified notion of "function".
--
Dr Jon D Harrop, Flying Frog Consultancy
OCaml for Scientists
http://www.ffconsultancy.com/produc...entists/?usenet
| |
| Jon Harrop 2007-08-02, 7:09 pm |
| Markus E.L. 2 wrote:
> let goto p = p ();;
There is no point in taking up this argument: it is based upon an incorrect
notion of "functional programming". So Rainer will reject all counter
examples.
--
Dr Jon D Harrop, Flying Frog Consultancy
OCaml for Scientists
http://www.ffconsultancy.com/produc...entists/?usenet
| |
| Rainer Joswig 2007-08-02, 7:09 pm |
| In article <f8tksn$bji$1@news.xmission.com>,
Thant Tessman <adm@standarddeviance.com> wrote:
> Rainer Joswig wrote:
>
> I'm serious. Can you come up with a compelling use of goto that's still
> compelling given a compiler that does tail-call optimization?
>
> -thant
Are we talking about language or implementation? Does FP
programming depend on the machine it runs on?
If a FP language enforces the use of functions for
imperative programming, then it is still
* enforcing FP
* enabling imperative programming
--
http://lispm.dyndns.org
| |
| Rainer Joswig 2007-08-02, 7:09 pm |
| In article <46b257c4$0$1598$ed2619ec@ptn-nntp-reader02.plus.net>,
Jon Harrop <jon@ffconsultancy.com> wrote:
> Rainer Joswig wrote:
>
> This is not consistent with my understanding of the term "functional
> programming".
>
>
> Computing 5! with no functions in SML:
>
> - val n = ref 5;
> val n = ref 5 : int ref
> - val result = ref 1;
> val result = ref 1 : int ref
> - while !n > 0 do (result := !n * !result; n := !n - 1);
> val it = () : unit
> - !result;
> val it = 120 : int
That makes SML
* supports imperative programming
* supports functional programming
but does not enforce them.
>
> However, this C implementation:
>
> int factorial(int n) { return n==0 ? 1 : n*factorial(n-1); }
>
> does not constitute "functional programming" as you imply.
No, no. I don't imply that.
> Nor are "let
> bindings" specific to functional programming. Nor does Lisp provide
> a "complete set of non-functional control flow constructs", the most
> obvious omission being pattern matching. Finally, this is all swinging on
> an ill-specified notion of "function".
Sure...
--
http://lispm.dyndns.org
| |
| Jon Harrop 2007-08-02, 7:09 pm |
| Rainer Joswig wrote:
> This is not 'visual programming'. It is 2d layout of
> text and symbols.
What exactly does visual programming provide beyond 2D layout of text and
symbols?
>
> See the standard library of ACL:
> ...
This seems to be a commercial vendor that adds some support for graphics to
the Common Lisp standard library rather than anything bundled with CL
itself.
--
Dr Jon D Harrop, Flying Frog Consultancy
OCaml for Scientists
http://www.ffconsultancy.com/produc...entists/?usenet
| |
| Rainer Joswig 2007-08-02, 7:09 pm |
| In article <a3ps25mtub.fsf@hod.lan.m-e-leypold.de>,
development-2006-8ecbb5cc8aREMOVETHIS@ANDTHATm-e-leypold.de (Markus
E.L. 2) wrote:
> Rainer Joswig wrote:
>
>
> What "please"? Does the intermediate form count? If no, then
>
> (a) A camlp4 macro achieving a syntax without let can be done.
>
> (b) It compiles into something in the vm which you won't recognize as
> closure or let.
>
> Would that qualify?
>
> -- M
>
> PS: And as I already expressed: Do we really have to use support of
> goto as a criterion how good a language is? Please (now from my
> side)! Last time I looked we we're a pretty time into the 21st
> century. I intend to stay there (all di vantages considered).
Markus, nobody talked about 'how good'.
I'll try explain again the context as I see it.
The question is whether a certain PL 'enforces' FP.
It is a difference if a certain paradigm is enforced,
supported, whatever, ...
This has nothing to do with good or bad. It just
means that to do any programming with some FPL
you may have to use the FP facilities. So, if
you call a function for a loop, it is still
a functional expression. If on the other hand the
language has a primitive loop construct, then it does not
enforce the use of FP for loops.
http://en.wikipedia.org/wiki/Imperative_programming
"is a programming paradigm that describes computation as
statements that change a program state"
How the process runs on the machine is not interesting.
On the level of the programming language, you
are using imperative or functional programming.
Compiling C to a functional programming language does
not make it a functional programming language. Compiling
pure FP programs to another program language using gotos does
not make the FP language an imperative language.
--
http://lispm.dyndns.org
| |
| Rainer Joswig 2007-08-02, 7:09 pm |
| In article <f8tn45$6f1$1@news.xmission.com>,
Thant Tessman <adm@standarddeviance.com> wrote:
> Rainer Joswig wrote:
>
> [...]
>
>
> I'm just wondering whether support for 'goto' specifically is a proper
> litmus test for whether or not a language supports imperative-style
> programming.
I would make a difference between
* imperative programming (loops, sequences of commands,
state changing operators, ...)
* imperative-style programming
> When I program in C or C++, I never use goto and would be
> suspicious of the programming talents of anyone who did. Does that mean
> I'm enforcing an FP programming style?
No.
> If a 'while' or 'for' construct is nothing but syntactic sugar in Scheme
> for some other arrangement of function calls and conditionals, but is
> otherwise identical in behavior to its imperative-style counterpart
> (including in the resulting compiled code), are we really imposing a
> functional style?
Yes.
>
> The last question is a bit more philosophical.
>
>
> -thant
--
http://lispm.dyndns.org
| |
| Rainer Joswig 2007-08-02, 7:09 pm |
| In article <46b25e5d$0$1620$ed2619ec@ptn-nntp-reader02.plus.net>,
Jon Harrop <jon@ffconsultancy.com> wrote:
> Rainer Joswig wrote:
>
> What exactly does visual programming provide beyond 2D layout of text and
> symbols?
See this program partitioning a list:
http://kogs-www.informatik.uni-hamb...s/partition.mpg
>
> This seems to be a commercial vendor that adds some support for graphics to
> the Common Lisp standard library rather than anything bundled with CL
> itself.
CLX and CLIM are the standard libraries. The vendor provides them.
--
http://lispm.dyndns.org
| |
| Rainer Joswig 2007-08-02, 7:09 pm |
| In article <3nr6mlleb4.fsf@hod.lan.m-e-leypold.de>,
development-2006-8ecbb5cc8aREMOVETHIS@ANDTHATm-e-leypold.de (Markus
E.L. 2) wrote:
> Rainer Joswig wrote:
>
>
> The second version is w/o let rec, BTW.
Ah, right. I missed that.
>
> Regards -- M
--
http://lispm.dyndns.org
| |
| Rainer Joswig 2007-08-02, 7:09 pm |
| In article <7mmyx9le2s.fsf@hod.lan.m-e-leypold.de>,
development-2006-8ecbb5cc8aREMOVETHIS@ANDTHATm-e-leypold.de (Markus
E.L. 2) wrote:
> Rainer Joswig wrote:
>
>
> So OCaml has non functional loops.
>
>
> OK. So while blocks and ref types are allowed. Bingo. My second
> example was imperative.
Right.
>
>
> Good.
>
>
> Good. It's basically a syntax thing then if the underlying language
> supports (a) tail calls
Providing 'tail calls' is a semantic thing. ;-)
> and (b) mutable variables. Since (eg) OCaml
> has a nice pre processor, imperative programming, even with gote
> (which is no requirement as I understand it) can be done.
>
>
> OK. I got a bit by your original reply since you ignored my
> 2nd take (with a while loop)
I missed that, sorry.
> and my reference to campl4 which would
> fix the rest of the surface syntax if anybody really cared.
>
> Regards -- Markus
--
http://lispm.dyndns.org
| |
| Jon Harrop 2007-08-02, 7:09 pm |
| Rainer Joswig wrote:
>
> No, no. I don't imply that.
Then you must agree that this equivalent OCaml is also not functional
programming:
# let rec factorial = function
| 0 -> 1
| n -> n * factorial(n-1);;
val factorial : int -> int = <fun>
--
Dr Jon D Harrop, Flying Frog Consultancy
OCaml for Scientists
http://www.ffconsultancy.com/produc...entists/?usenet
| |
| Rainer Joswig 2007-08-02, 7:09 pm |
| In article <46b26524$0$1592$ed2619ec@ptn-nntp-reader02.plus.net>,
Jon Harrop <jon@ffconsultancy.com> wrote:
> Rainer Joswig wrote:
>
> Then you must agree that this equivalent OCaml is also not functional
> programming:
>
> # let rec factorial = function
> | 0 -> 1
> | n -> n * factorial(n-1);;
> val factorial : int -> int = <fun>
No.
--
http://lispm.dyndns.org
| |
| Rainer Joswig 2007-08-02, 7:09 pm |
| In article <xy7iodldmd.fsf@hod.lan.m-e-leypold.de>,
development-2006-8ecbb5cc8aREMOVETHIS@ANDTHATm-e-leypold.de (Markus
E.L. 2) wrote:
> Rainer Joswig wrote:
>
>
>
> let rec loop () =
>
> action;
>
> if condition then loop ()
> in loop ()
>
>
> vs.
>
> repeat
> action
> until condition
>
>
> - hardly a really significant difference. Funtional style IMHO is more
> than superficial syntax.
Right.
>
> Regards -- Markus
--
http://lispm.dyndns.org
| |
| Jon Harrop 2007-08-02, 7:09 pm |
| Joachim Durchholz wrote:
>
> OK, now that's something that isn't directly representable in a compiled
> language.
No. That is entirely feasible in compiled languages. Both OCaml and F# have
interactive top-levels that are extensible and compiled to native code.
These are already in extensive use by the scientific community, for
example, and products like our "F# for Visualization" make graphics
interactive too.
--
Dr Jon D Harrop, Flying Frog Consultancy
OCaml for Scientists
http://www.ffconsultancy.com/produc...entists/?usenet
| |
| Rainer Joswig 2007-08-02, 7:09 pm |
| In article <q3fy31jyd4.fsf@hod.lan.m-e-leypold.de>,
development-2006-8ecbb5cc8aREMOVETHIS@ANDTHATm-e-leypold.de (Markus
E.L. 2) wrote:
> Rainer Joswig wrote:
>
>
> Why?
Because functions in C are really 'procedures'. The C example is written in a functional style.
Functions in OCAML are 'functions'. The OCAML example is written in a FPL using
the built-in FP constructs.
> Let me offer a compromise: The borders between functional and
> imperative are really blurred. Using let and fun doesn't make a
> program function even if the syntax looks a bit like it. Passing
> closures around is what makes programs functional (w already had this
> definition once in this thread of the other, I don't rememember). And style is more than a single program.
>
> So Id advocate
>
> let n = ref ...;;
> let result = ref ...
>
> let rec loop () =
>
> ....
>
> in loop ();;
>
> as being imperative style
Right. 'Style'.
See: http://mitpress.mit.edu/sicp/full-t...ook-Z-H-11.html
> (no passing of closures, no passing of
> arguments to functions even, but mutating storage) whereas Jons C
> program is functional on the ground of all state being passed with the
> function invocation.
>
> Of course a single example ("I can write this in style X") doesn't
> make a language a X-style-language, whatever. This is something that
> has to be found in the whole language design and in the borderline
> cases is rarely clear cut.
>
> Regards -- Markus (driveling)
--
http://lispm.dyndns.org
| |
| Jon Harrop 2007-08-02, 7:09 pm |
| Rainer Joswig wrote:
> Because functions in C are really 'procedures'. Functions in OCAML
> are 'functions'.
What exactly is the difference between "procedure" and "function" here?
--
Dr Jon D Harrop, Flying Frog Consultancy
OCaml for Scientists
http://www.ffconsultancy.com/produc...entists/?usenet
| |
|
|
| Rainer Joswig 2007-08-02, 10:07 pm |
| In article <hek5sdih6r.fsf@hod.lan.m-e-leypold.de>,
development-2006-8ecbb5cc8aREMOVETHIS@ANDTHATm-e-leypold.de (Markus
E.L. 2) wrote:
> Rainer Joswig wrote:
>
>
> Perhaps you meant the difference between procedures and closures?
No, not really.
The distinction is a bit blurry. I'll try:
a procedure
* has a name
* wraps a sequence of statements
* may be called with arguments and may return a value
(or use the mechanism of In/Out arguments or similar)
* may be accessed and passed via a 'pointer'
a function
* follows the idea of mathematical functions (say, some lambda calculus)
* may be called with arguments and may return a value
* can be passed to functions and returned from functions
* can form a closure when combined with a lexical environment
>
>
> I don't think that will earn you any gratitude. Don't know why.
>
> Regards -- Markus
--
http://lispm.dyndns.org
| |
| Paul Rubin 2007-08-03, 4:17 am |
| Date: 03 Aug 2007 00:01:08 -0700
Message-ID: <7x643x3xvv.fsf@ruckus.brouhaha.com>
Organization: Nightsong/Fort GNOX
User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Lines: 14
NNTP-Posting-Date: 03 Aug 2007 02:01:08 CDT
X-Complaints-To: abuse@octanews.net
Bytes: 1704
X-Original-Bytes: 1661
Xref: number1.nntp.dca.giganews.com comp.lang.functional:62964
Bruno Desthuilliers <bdesth.quelquechose@free.quelquepart.fr> writes:
> I admit I didn't go that far with Haskell, so I may be wrong, but I
> don't get how IO could be totally side-effect free. But it probably
> depends on the definition of 'side-effects', and on lots of other
> things I do ignore. FWIW (ok, I bet this is a FAQ, but...) would you
> mind recommanding some online resource on this that a
> mathematics-illiterate self-taught programmer could understand ?
Since you use Python, you might like this:
http://lukeplant.me.uk/blog.php?id=1107301643
IO in Haskell is done by threading the "outside world" through
a chain of neste function calls like the monads described in that
blog post.
| |
| rossberg@ps.uni-sb.de 2007-08-03, 8:05 am |
| On 3 Aug., 01:01, Rainer Joswig <jos...@lisp.de> wrote:
>
>
> Yes.
In SML, qua language definition,
while E1 do E2
is simply sugar for
let fun f() = if E1 then (E2; f()) else ()
in f() end
Sequencing
(E1 ; ... ; En)
roughly is sugar for
(fn X1 => ... => fn Xn => Xn) E1 ... En
However, there is no way to observe this desugaring, and hence
implementations are free to compile it however they want. The
desugaring is *only* given to define the *semantics* of the constructs
in terms of existing ones, it has no impact whatsoever on their use.
I.e., as a programmer, you couldn't care less.
Nevertheless, under your argument, the way the language is formally
defined makes the difference between imperative and not imperative.
That does not make a whole lot of sense.
- Andreas
| |
| rossberg@ps.uni-sb.de 2007-08-03, 8:05 am |
| On 3 Aug., 02:44, Rainer Joswig <jos...@lisp.de> wrote:
>
> a procedure
> * has a name
> * wraps a sequence of statements
> * may be called with arguments and may return a value
> (or use the mechanism of In/Out arguments or similar)
> * may be accessed and passed via a 'pointer'
>
> a function
> * follows the idea of mathematical functions (say, some lambda calculus)
> * may be called with arguments and may return a value
> * can be passed to functions and returned from functions
> * can form a closure when combined with a lexical environment
If you step back for a minute you'll realise that wrt to most of your
list a function is merely a generalisation of a procedure (if we
accept your definition). I don't understand why generalising a
construct alone should enforce something wrt to the programmer.
The only fundamental point is rather a consequence of something else:
I think the presence of a statement/expression schisma is more
characteristic of an imperative language (which is why Python is not
functional, despite having functions in the sense above). On the other
hand, there have been languages that clearly were imperative, but did
not have this distinction, e.g. Algol 68.
I think it is hopeless to try nailing down the paradigm(s) of a
language based on clear-cut definitions. In the end, it boils down to
what programming style the language supports well and what is
predominant in the community.
- Andreas
| |
| Rainer Joswig 2007-08-03, 8:05 am |
| In article <1186136604.516503.277020@22g2000hsm.googlegroups.com>,
rossberg@ps.uni-sb.de wrote:
> On 3 Aug., 01:01, Rainer Joswig <jos...@lisp.de> wrote:
>
> In SML, qua language definition,
>
> while E1 do E2
>
> is simply sugar for
>
> let fun f() = if E1 then (E2; f()) else ()
> in f() end
What does 'sugar' mean in this context?
What does the definition for 'while' look like?
I think it is still kind of unfortunate that there
seems to be no language reference for SML online.
>
> Sequencing
>
> (E1 ; ... ; En)
>
> roughly is sugar for
>
> (fn X1 => ... => fn Xn => Xn) E1 ... En
>
> However, there is no way to observe this desugaring, and hence
> implementations are free to compile it however they want. The
> desugaring is *only* given to define the *semantics* of the constructs
> in terms of existing ones, it has no impact whatsoever on their use.
> I.e., as a programmer, you couldn't care less.
>
> Nevertheless, under your argument, the way the language is formally
> defined makes the difference between imperative and not imperative.
> That does not make a whole lot of sense.
>
> - Andreas
--
http://lispm.dyndns.org
| |
| Paul Rubin 2007-08-03, 8:05 am |
| Rainer Joswig <joswig@lisp.de> writes:
> What does 'sugar' mean in this context?
It means it's sort of like a macro.
> I think it is still kind of unfortunate that there
> seems to be no language reference for SML online.
http://www.cs.cmu.edu/afs/cs.cmu.ed...mosaic/sml.html
| |
|
|
| Paul Rubin 2007-08-03, 8:05 am |
| Rainer Joswig <joswig@lisp.de> writes:
> Which of the links on the page points to a language reference document?
There are some reference materials at the link to "reference" or
soemthing like that. I don't think the actual language spec is
accessible online. There is a dead tree book:
http://mitpress.mit.edu/book-home.tcl?isbn=0262631814
| |
| rossberg@ps.uni-sb.de 2007-08-03, 8:05 am |
| On 3 Aug., 12:47, Rainer Joswig <jos...@lisp.de> wrote:
> rossb...@ps.uni-sb.de wrote:
>
> What does 'sugar' mean in this context?
That formally, it is merely a syntactic abbreviation.
> What does the definition for 'while' look like?
Um, I just gave it above.
- Andreas
| |
| Rainer Joswig 2007-08-03, 8:05 am |
| In article <1186140771.204641.31180@w3g2000hsg.googlegroups.com>,
rossberg@ps.uni-sb.de wrote:
> On 3 Aug., 12:47, Rainer Joswig <jos...@lisp.de> wrote:
>
> That formally, it is merely a syntactic abbreviation.
>
>
> Um, I just gave it above.
Is that the one in the language standard?
>
> - Andreas
--
http://lispm.dyndns.org
| |
| Rainer Joswig 2007-08-03, 8:05 am |
| In article <7xd4y4q2f2.fsf@ruckus.brouhaha.com>,
Paul Rubin <http://phr.cx@NOSPAM.invalid> wrote:
> Rainer Joswig <joswig@lisp.de> writes:
>
> There are some reference materials at the link to "reference" or
> soemthing like that.
The FAQ link is dead. The link to Appel's page is dead.
The link to a list of projects is dead.
The link to the base lib is dead (though the mirror works).
> I don't think the actual language spec is
> accessible online. There is a dead tree book:
>
> http://mitpress.mit.edu/book-home.tcl?isbn=0262631814
I'd say it would be extremely useful to have a HTML version of that
book online.
Haskell has the 'revised report' online:
http://haskell.org/onlinereport/
CL has a derived version of the ANSI CL Spec online:
http://www.lispworks.com/documentat...Front/index.htm
It is quite usual for development environments to reference
these documents for language constructs...
--
http://lispm.dyndns.org
| |
| rossberg@ps.uni-sb.de 2007-08-03, 8:05 am |
| On 3 Aug., 13:37, Rainer Joswig <jos...@lisp.de> wrote:
>
>
>
[color=darkred]
> Is that the one in the language standard?
Yes.
- Andreas
| |
| Rainer Joswig 2007-08-03, 8:05 am |
| In article <1186141759.647357.203560@d55g2000hsg.googlegroups.com>,
rossberg@ps.uni-sb.de wrote:
> On 3 Aug., 13:37, Rainer Joswig <jos...@lisp.de> wrote:
>
>
> Yes.
>
> - Andreas
Interesting. What kind of transformation is it? How
does it deal with while f() ... , where f is the
same f as above?
--
http://lispm.dyndns.org
| |
| rossberg@ps.uni-sb.de 2007-08-03, 8:05 am |
| On 3 Aug., 13:52, Rainer Joswig <jos...@lisp.de> wrote:
>
>
>
>
> Interesting. What kind of transformation is it?
Kind of transformation?
> How
> does it deal with while f() ... , where f is the
> same f as above?
Of course, there is a side condition saying that the f in the
expansion must be chosen fresh wrt E1 and E2 (the actual definition
uses a meta variable for that).
A significant part of the SML grammar, btw, is defined in terms of
such "derived forms", the "bare" language is quite small.
- Andreas
| |
| Rainer Joswig 2007-08-03, 8:05 am |
| In article <1186144426.398439.294560@l70g2000hse.googlegroups.com>,
rossberg@ps.uni-sb.de wrote:
> On 3 Aug., 13:52, Rainer Joswig <jos...@lisp.de> wrote:
>
> Kind of transformation?
>
>
> Of course, there is a side condition saying that the f in the
> expansion must be chosen fresh wrt E1 and E2 (the actual definition
> uses a meta variable for that).
>
> A significant part of the SML grammar, btw, is defined in terms of
> such "derived forms", the "bare" language is quite small.
What are the imperative constructs in the "bare" language?
> - Andreas
--
http://lispm.dyndns.org
| |
| rossberg@ps.uni-sb.de 2007-08-03, 7:11 pm |
| On 3 Aug., 14:59, Rainer Joswig <jos...@lisp.de> wrote:
>
>
> What are the imperative constructs in the "bare" language?
Basically, only mutable references. Everything else is either
syntactic sugar or a library issue (e.g. arrays and I/O).
- Andreas
| |
| rossberg@ps.uni-sb.de 2007-08-03, 7:11 pm |
| On 3 Aug., 16:54, rossb...@ps.uni-sb.de wrote:
>
>
>
> Basically, only mutable references. Everything else is either
> syntactic sugar or a library issue (e.g. arrays and I/O).
Oh, and I should not forget exceptions, which are also in the bare
language.
- Andreas
| |
| Paul Rubin 2007-08-04, 10:12 pm |
| "Dimiter \"malkia\" Stanev" <malkia@gmail.com> writes:
> At my daily job, I'm forced to use C++ without exceptions (console
> video game developer), so this forces me to use goto's:
> void* allocateThreeLinkedMemoryBlocks(int size1, int size2, int size3)
> {
> void *ptr1, *ptr2, *ptr3;
>
> ptr1 = allocateMemoryBlock( size1 );
> if( ptr1 == NULL )
> goto cleanup;
> ...
> cleanup:;
> deallocateMemoryBlock( ptr1 );
> deallocateMemoryBlock( ptr2 );
> deallocateMemoryBlock( ptr3 );
I hope that's not real code. If the first allocation fails, this
deallocates ptr2 and ptr3 which are uninitialized pointers so all hell
may break loose.
| |
| Ivan Jager 2007-08-09, 7:10 pm |
| On 2007-08-03, rossberg@ps.uni-sb.de <rossberg@ps.uni-sb.de> wrote:
> On 3 Aug., 13:52, Rainer Joswig <jos...@lisp.de> wrote:
>
> Kind of transformation?
>
>
> Of course, there is a side condition saying that the f in the
> expansion must be chosen fresh wrt E1 and E2 (the actual definition
> uses a meta variable for that).
>
> A significant part of the SML grammar, btw, is defined in terms of
> such "derived forms", the "bare" language is quite small.
Alternately, you could define
while E1 do E2
as
let
val c = fn() => E1
val b = fn() => E2
in
let fun f() = if c() then (b(); f()) else ()
in f()
end end
Which would allow it to actually be pure syntactic sugar rather than
a translation that needs to be done in the elaborator.
Ivan
| |
| rossberg@ps.uni-sb.de 2007-08-10, 4:23 am |
| On 10 Aug., 01:08, Ivan Jager <aij+nos...@andrew.cmu.edu> wrote:
>
>
>
[color=darkred]
[color=darkred]
> Alternately, you could define
> while E1 do E2
> as
> let
> val c = fn() => E1
> val b = fn() => E2
> in
> let fun f() = if c() then (b(); f()) else ()
> in f()
> end end
>
> Which would allow it to actually be pure syntactic sugar rather than
> a translation that needs to be done in the elaborator.
There is no difference, you still would have to ensure that c does not
occur in E2. In SML you /could/ avoid it by writing
val c = fn() => E1
and b = fn() => E2
or
val (c,b) = (fn() => E1, fn() => E2)
But there is not much of an issue either way - you just generate fresh
identifiers of a form that cannot appear in source code. No need to
start an elaborator for that.
| |
| Ivan Jager 2007-08-10, 7:08 pm |
| On 2007-08-10, rossberg@ps.uni-sb.de <rossberg@ps.uni-sb.de> wrote:
> On 10 Aug., 01:08, Ivan Jager <aij+nos...@andrew.cmu.edu> wrote:
>
>
>
> There is no difference, you still would have to ensure that c does not
> occur in E2. In SML you /could/ avoid it by writing
>
> val c = fn() => E1
> and b = fn() => E2
>
> or
>
> val (c,b) = (fn() => E1, fn() => E2)
>
> But there is not much of an issue either way - you just generate fresh
> identifiers of a form that cannot appear in source code. No need to
> start an elaborator for that.
Oops. I wrote it properly in ocaml, and then broke it while translating
it to SML. :P
| |
| Jon Harrop 2007-08-11, 4:28 am |
| rossberg@ps.uni-sb.de wrote:
> But there is not much of an issue either way - you just generate fresh
> identifiers of a form that cannot appear in source code.
That's rather a grim solution, IMHO. I think you can always avoid it with
judicious use of closures...
--
Dr Jon D Harrop, Flying Frog Consultancy
OCaml for Scientists
http://www.ffconsultancy.com/produc...entists/?usenet
| |
| rossberg@ps.uni-sb.de 2007-08-11, 7:09 pm |
| On 11 Aug., 09:39, Jon Harrop <j...@ffconsultancy.com> wrote:
> rossb...@ps.uni-sb.de wrote:
>
> That's rather a grim solution, IMHO. I think you can always avoid it with
> judicious use of closures...
No. You could use functional abstraction for derived forms of
expressions, but it doesn't save you for other phrase classes such as
types, declarations, modules, signature specifications etc, because
you cannot abstract over them - and SML has derived forms for all of
those. For example,
functor F (Specs) = M
rewrites to
functor F (X : sig Specs end) = let open X in M end
No abstraction trick applies here.
- Andreas
| |
| Jon Harrop 2007-08-12, 7:07 pm |
| rossberg@ps.uni-sb.de wrote:
> On 11 Aug., 09:39, Jon Harrop <j...@ffconsultancy.com> wrote:
>
> No. You could use functional abstraction for derived forms of
> expressions, but it doesn't save you for other phrase classes such as
> types, declarations, modules, signature specifications...
Oh right. Hadn't thought of those. :-)
--
Dr Jon D Harrop, Flying Frog Consultancy
OCaml for Scientists
http://www.ffconsultancy.com/produc...entists/?usenet
| |
|
|
|
|
|