From: Siegfried Gonzi <siegfried.gonzi@kfunigraz.ac.at>
Subject: Re: Ada communicating with other programs
Date: Tue, 20 Nov 2001 16:29:31 +0100
Date: 2001-11-20T15:33:28+00:00 [thread overview]
Message-ID: <3BFA76DA.4BDD8F36@kfunigraz.ac.at> (raw)
In-Reply-To: mailman.1006267245.26903.comp.lang.ada@ada.eu.org
"M. A. Alves" schrieb:
> > I often have to deal with big array computations. Currently, I am
> > using Clean
>
> Give us a reference, please.
Clean should not become the subject here. A google search will quickly
delegate you to their homepage:
http://www.cs.kun.nl/~clean/
> > aa) Is it hard in Ada to do "semi command line programming".
>
> What is that?
In Yorick (or Scilab or Matlab) you can do something like this:
a=span(0.0,Pi,100) //creating an array from 0.0 to Pi with 100 points
b=fft(a) //doing the FFT
plg,a //plotting the FFT
In Clean I do not have the command line (Matlab or Yorick are interpreters)
and I have to compile my program:
e.g. creating a 2 dimensional array filled up with values ranging from 0.0 to
N (for every row):
Clean program:
==
module makeArray
importStdEnv
makeArray:: !Int !Int -> !{#{#Real}}
makeArray row column = { { j \\ j <- [0..(column-1)] } \\ i <- [0..(row-1)] }
Start = makeArray 3 3
==
I can use it only after compiling (compiling and linking is the same process
in Clean). The array is safe and under the protection of garbage-collection; I
could even not call it with inappropiate types,e.g.
Start = makeArray 3.0 3.0
> > The Clean program consits of nearly 100 lines of code. I ask here "how
> > easy can it be in Ada", because I have been really depressed and asked
> > myself why I have to waste my time with such things and is there a
> > clearer way extracting the values.
>
> It is very easy to do it in Ada, but do expect a big number of lines. If
> you want tersness use a "write-only" language like any of the C
> derivatives outhere e.g. PERL---but then be prepare to waste some serious
> time chasing bugs.
>
Tersness is not my aim (Clean is also a language for re-using code). But I had
a hard time to implement it in Clean, because I had to implement some
primitives by myself (okay, with pattern-matching �t has been not too time
consuming). At the end of the post is a code snippet of the core-code which
reads in from a file.
>
> You you cleary state the specs for the program you're currently
> implementing in 100-lines of Clean I can try to show you how to do it in
> Ada as your first tutorial ;-)
The task was to read the following file into an array( the line numbers and
the number of array columns are not know; only the number of header lines are
know):
here is
a header
line and maybe
many more
Day,Time,Val1,Val2,...
01:23:2001,12:23:34,2.3445,233.34,...
02:03:2001,13:45:00,2,344,222.34,...
....
....
> > c) Is there an aha experience when one is confronted in Ada with "not
> > having the goody called garbage-collection".
>
> I haven't felt the need for that yet. In Ada you can do everything
> keeping the variables under a nice (dynamic as well as static) scope.
> (And of course some guys will tell you how garbage collection slows things
> down.)
In worse cases Clean is only 2 times slower as a tuned (but not inlined) C
code. For example a 2 dimensional 1024x1024 FFT in Clean is about 1.5 to 2
times slower as the same C version. The garbage-collection in Clean is one of
the best I know (maybe some commercial Lisps are in that ligue).
> Welcome to Ada ;-)
Time will show...
S. Gonzi
Only for the curiosity
==
ADatumTimeStringRead:: !Char !Char {!*{!Real}} !File -> {!*{!Real}}
ADatumTimeStringRead char char_d marray file = fill_up 0 marray file
where
fill_up:: !Int {!*{!Real}} !File -> {!*{!Real}}
fill_up n marray file
| n == (size marray) = marray
#! (string, file) = sfreadline file
#! elem = (RealfromDatumTime_String char_d
(DStringtoString_List char string))
#! elemo = {x\\x<- elem}
= fill_up (n+1) { marray & [n] = elemo } file
RealfromDatum_String:: !Char ![!String] -> ![!Real]
RealfromDatum_String char [] = []
RealfromDatum_String char [x,y:r] = [ Datum_StringtoReal char x ,
Time_StringtoReal char y : RealfromString r ]
RealfromDatumTime_String:: !Char ![!String] -> ![!Real]
RealfromDatumTime_String char [] = []
RealfromDatumTime_String char [x,y:r] = [ (Datum_StringtoReal char x) +
(Time_StringtoReal char y) : RealfromString r ]
Time_StringtoReal:: !Char !String -> !Real
Time_StringtoReal char string = (toReal(hour) + ((toReal(minute))/60.0) +
((toReal(second))/3600.0) ) / 24.0
where
string_list = StringtoString_List char string
hour = string_list !! 0
minute = string_list !! 1
second = string_list !! 2
Datum_StringtoReal:: !Char !String -> !Real
Datum_StringtoReal char string = toReal (day) + toReal ( months !! (toInt
month) )
where
string_list = StringtoString_List char string
day = string_list !! 0
month = string_list !! 1
year = toInt (string_list !! 2)
//year:: !Int
//year
// | toInt (string_list !! 2) >= 0 = toInt (string_list !! 2) +
2000
// = toInt (string_list !! 2) + 1900
//
months:: [!Real]
months
| ( leap year ) =
[0.0,0.0,31.0,60.0,91.0,121.0,152.0,182.0,213.0,244.0,274.0,305.0,335.0]
=
[0.0,0.0,31.0,59.0,90.0,120.0,151.0,181.0,212.0,243.0,273.0,304.0,334.0]
//
leap :: !Int -> Bool
leap y
| divisible y 100 = divisible y 400
= divisible y 4
//
divisible :: !Int !Int -> Bool
divisible t n = t rem n == 0
==
AND SO ON
next prev parent reply other threads:[~2001-11-20 15:29 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-11-20 13:10 Ada communicating with other programs Siegfried Gonzi
2001-11-20 14:39 ` M. A. Alves
2001-11-20 15:29 ` Siegfried Gonzi [this message]
2001-11-20 15:47 ` Preben Randhol
2001-11-20 16:35 ` M. A. Alves
2001-11-20 16:44 ` Preben Randhol
2001-11-20 16:51 ` Larry Kilgallen
2001-11-20 19:27 ` Pascal Obry
2001-11-20 19:48 ` Preben Randhol
2001-11-20 20:29 ` Ted Dennison
2001-11-20 23:14 ` tmoran
2001-11-21 9:03 ` Preben Randhol
2001-11-20 16:24 ` Jacob Sparre Andersen
2001-11-20 16:55 ` Larry Kilgallen
2001-11-20 19:52 ` Mark Lundquist
2001-11-20 19:59 ` Preben Randhol
2001-11-21 2:20 ` Larry Kilgallen
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox