Betr.: [clean-list] Passing commandline arguments to a clean program

Sander van den Berg xkb@hypernation.net
Tue, 7 Sep 2004 17:04:44 +0200


--Apple-Mail-5-298167258
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed

Thanks for all the help. I finished my little test program. Its working 
fine right now except for the following:

Whenever I try to generate the Character Frequency table of a large 
text file, I get either heap full or stack errors, even when I increase 
the heap-size.

I attached the program.

Are there any other things I could improve on the code?

Regards,

Sander

--Apple-Mail-5-298167258
Content-Transfer-Encoding: quoted-printable
Content-Type: application/text;
	x-mac-type=54455854;
	x-unix-mode=0644;
	x-mac-creator=646F7361;
	name="CharFreq.icl"
Content-Disposition: attachment;
	filename=CharFreq.icl

module=20filetest=0D=0Dimport=20StdEnv,=20ArgEnv=0D=0D::=20FreqList=20=
:=3D=3D=20[(Char,Int)]=0D=0Dfilename=20::=20String=0Dfilename=20=3D=20=
"testfile.txt"=0D=0Dfreq=20::=20[Char]=20FreqList=20->=20FreqList=0Dfreq=20=
[]=20xs=20=09=09=3D=20xs=0Dfreq=20[x:xs]=20ys=20=09=3D=20freq=20xs=20=
(inSet=20x=20ys)=0D=0DinSet=20::=20Char=20FreqList=20->=20FreqList=0D=
inSet=20a=20[]=20=3D=20[(a,1)]=0DinSet=20a=20xs=0D=09|=20lookup=20a=20xs=09=
=3D=20increaseElement=20a=20xs=0D=09|=20otherwise=09=09=3D=20xs=20++=20=
[(a,1)]=0D=0DincreaseElement=20::=20Char=20FreqList=20->=20FreqList=0D=
increaseElement=20a=20[]=20=3D=20[]=0DincreaseElement=20a=20[x:xs]=0D=09=
|=20a=3D=3Dfst=20x=09=3D=20[(a,=20(snd=20x)+1)]=20++=20increaseElement=20=
a=20xs=0D=09|=20otherwise=09=3D=20[x]=20++=20increaseElement=20a=20xs=0D=0D=
lookup=20::=20Char=20FreqList=20->=20Bool=0Dlookup=20x=20[]=20=3D=20=
False=0Dlookup=20x=20[y:ys]=0D=09|=20x=3D=3Dfst=20y=09=3D=20True=0D=09|=20=
otherwise=09=3D=20lookup=20x=20ys=0D=0Dhead=20::=20[a]=20->=20a=0Dhead=20=
[x:xs]=20=3D=20x=0D=0D//Quicksort=20op=20snd=20x=0DfreqListSort=20::=20=
FreqList=20->=20FreqList=0DfreqListSort=20[]=20=09=3D=20[]=0D=
freqListSort=20[x:xs]=20=3D=20freqListSort=20[z=20\\=20z<-xs=20|snd=20=
z<=3D=20snd=20x]=20++=20[x]=20++=20freqListSort=20[z=20\\=20z<-xs=20|snd=20=
z=20>=20snd=20x]=0D=0DreadChar=20::=20File=20->=20[Char]=0DreadChar=20f=0D=
=09|=20not=20readok=20=09=3D=20[]=0D=09|=20otherwise=09=09=3D=20[=20char=20=
:=20readChar=20alteredfile=20]=0Dwhere=0D=09(readok,char,alteredfile)=20=
=3D=20sfreadc=20f=0D=09=0D=0DopenFile=20::=20String=20*env=20->=20=
(File,*env)=20|=20FileSystem=20env=0DopenFile=20""=20fs=20=3D=20abort=20=
"no=20filename=20passed"=0DopenFile=20a=20fs=0D=09|=20not=20openok=09=3D=20=
abort=20("error=20opening=20filename=20"=20+++=20a)=0D=09|=20otherwise=20=
=09=3D=20(file,fsa)=0Dwhere=0D=09(openok,file,fsa)=09=3D=20sfopen=20a=20=
FReadText=20fs=0D=09=0DmkString=20::=20FreqList=20->=20String=0DmkString=20=
[]=20=09=3D=20""=0DmkString=20[x:xs]=20=3D=20"Char:=20"+++=20(toString=20=
o=20fst)=20x=20+++=20"=20freq:=20"=20+++=20(toString=20o=20snd)=20x=20=
+++=20"\n"=20+++=20mkString=20xs=0D=0D=0DcheckParam=20::=20{.{#Char}}=20=
->=20String=0DcheckParam=20s=0D=09|=20not=20(paramsize=20=3D=3D=201)=09=3D=
=20abort=20"wrong=20nr=20of=20arguments"=0D=09|=20otherwise=09=09=09=09=3D=
=20s.[1]=0Dwhere=0D=09paramsize=20=3D=20(size=20s)=20-=201=0D=09=0D=
//open=20a=20file,=20read=20the=20chars=20and=20print=20them=0DStart=20=
::=20*World=20->=20*World=0DStart=20world=0D=09#=09(console,=20world)=09=09=
=3D=20stdio=20world=0D=09=09console=09=09=09=09=09=3D=20fwrites=20"meest=20=
voorkomende=20char:=20\n"=20console=0D=09#=09argv=09=09=09=09=09=3D=20=
getCommandLine=0D=09=09(file,world)=09=09=09=3D=20openFile=20(checkParam=20=
argv)=20world=0D=09#=09freqlist=09=09=09=09=3D=20freqListSort=20(freq=20=
(readChar=20file)=20[])=0D=09=09console=20=09=09=09=09=3D=20fwrites=20=
((mkString=20o=20reverse)=20freqlist)=20console=0D=09=09(ok,world)=09=09=09=
=09=3D=20fclose=20console=20world=0D=09|=09not=20ok=09=09=09=09=09=3D=20=
abort=20"Cannot=20close=20console"=0D=09|=09otherwise=09=09=09=09=3D=20=
world=0D=

--Apple-Mail-5-298167258
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed


On 7-sep-04, at 14:23, Paul de Mast wrote:

> Hello Sander,
>
> You can use the function:
>
> 	getCommandLine :: {.{#Char}}
>
> from module ArgEnv
>
> For example:
>
> import ArgEnv
>
> Start
> = (argc,argv)
> where
> 	argc				= length argv - 1
> 	argv				=  [toString w \\ w <-:
> getCommandLine]
>
> regards,
>
> Paul de Mast
>
>>>> Sander van den Berg <xkb@hypernation.net> 7-9-2004 11:24:18 >>>
> Hello list,
>
> Is it possible to pass commandline arguments to a Clean program.
>
> For example:
> freqList filename.txt
>
> and in freqList:
>
> Start :: *world -> *world
> Start = makeFreqList (openfile command_line_argument)
>
> (Just an example, not working or anything)
>
> Regards,
>
> Sander
>
>
> _______________________________________________
> clean-list mailing list
> clean-list@cs.kun.nl
> http://www.cs.kun.nl/mailman/listinfo/clean-list

--Apple-Mail-5-298167258--