[clean-list] (no subject)

John van Groningen johnvg at cs.ru.nl
Tue Feb 27 17:08:56 MET 2007


Timothy Hochberg wrote:
>I've been playing with Clean for a few weeks now and I have a few 
>questions and observations, more about infrastructure of Clean than 
>the language itself:
>
>* The profiler overflows for me: I tend to get negative time value, 
>which makes it difficult to interpret the results. It's possible 
>that this is related to running the code on a dual core processor 
>since I didn't encounter this when I ran similar code on a single 
>core machine. I'm not certain though, since it wasn't exactly the 
>same code. Is this a known issue? I can provide examples if you like.

The time profiler uses the time stamp counter (TSC) of the processor. 
It is possible that different cores have different values for the 
TSC. This
could cause negative time values when profiling, if a thread is executed
by more than one core.

Could you try adding the following 2 functions:

GetCurrentThread :: Int;
GetCurrentThread = code {
	ccall GetCurrentThread at 0 "P:I"
}

SetThreadAffinityMask :: !Int !Int -> Int;
SetThreadAffinityMask thread_h thread_afinity_mask = code {
	ccall SetThreadAffinityMask at 8 "PII:I"
}

And call the functions at the beginning of the program:

Start
	| SetThreadAffinityMask GetCurrentThread 1<>0

To be able to link the program, add an extra line with:
SetThreadAffinityMask at 8
at the end of the kernel_library file in the directory
Libraries\StdEnv\Clean System Files
using the CleanIDE or another text editor.

This should cause the program to be executed by one core only, and
hopefully solve the problem with the profiler. If it doesn't, could
you send us an example ?

For very small functions, that are not recursive, negative time values
are sometimes reported by the profiler, because it tries to subtract the
overhead caused by profiling from the measured execution time, and sometimes
the computed overhead is a bit too large.

>* While I'm on the subject, is there some documentation on how to 
>interpret the mangled names that show up in the profiler? 
>"g_cl;100;54;82" for example?

I couldn't find g_cl, maybe you mean g_c1 ?

>I'm guessing that this is some anonymous function defined on line 
>100? Is that correct?

Yes.

>And is there more information that can be deduced from the name?

If it is g_c1 or g_c2, then it is generated for a comprehension.

>* The first time some text is drawn in the window, it seems to go to 
>the wrong place. In particular the example in section 5.4.3 of the 
>ObjectIO tutorial:
>     example = drawAt zero "Pop"
>puts the text in the wrong place until the window is resized. If the 
>window is minimized and then restored, the text is once again in the 
>wrong place.

I haven't tried this yet.

>* The non ObjectIO games have a horrible, seizure inducing flicker 
>on my machine. Otherwise they're pretty cool.

This doesn't happen on my computer.

>* Some of the examples run way too fast. Bounce, for example, needed 
>some delay inserted before I could see what was going on.

Yes, some examples were written on much slower computers.

>* Having the IDE written in Clean is good marketing! However, the 
>IDE seems needlessly crippled by having only a single level of undo. 
>Is there some way of activating multi level undo that I am missing?

No, as far as I know.

>  It would also be nice to be able to bind block comment (AKA "Add 
>Prefix") to a key, but it doesn't look like that is possible.

Or use /* and */ instead (nested comments are allowed in Clean).

>* I'm interested in calling into clean from another language (Python 
>to be specific). I found some documentation on how to call into 
>Clean as long as I use Ints[1]. A little bit more digging[2] 
>revealed that there is some experimental code to allow Reals and 
>Strings and maybe someday {#Int} and {#Real}. For the stuff I'd like 
>to try those last two would be critical, so let this be a vote for 
>getting those implemented.
>
>[1] 
><http://www.xs4all.nl/~keslr/functional/clean/howto/cleandll.html>http://www.xs4all.nl/~keslr/functional/clean/howto/cleandll.html
>[2] 
><http://article.gmane.org/gmane.comp.lang.clean/883>http://article.gmane.org/gmane.comp.lang.clean/883

I have implemented foreign export of {#Int} and {#Real}, and updated:

http://clean.cs.ru.nl/download/Clean22/windows/Clean_2.2_extended_foreign_export.zip

To use this compiler:
- copy the .exe and .dll files in the zip file into the Tools/Clean 
System directory of Clean 2.2.
- copy the .o files in the zip file into the Libraries/StdEnv/Clean 
System Files directory of Clean 2.2
(in both cases overwriting the old files with the new version).

The file Tools/htoclean/Clean.h contains some macros for accessing the arrays.

If an array is passed from Clean to c, the c function is passed a pointer to
an array inside Clean's heap. This pointer should not be used any more after
the c function returns, because the garbage collector may move or deallocate
the array.

To pass an array from c to Clean, the int (4 bytes) at (byte) offset -8,
should contain the number of elements of the array. A copy of this array is
made in the Clean heap when the c function returns, and this copy is used.

The c programmer is responsible for releasing any memory allocated
for these arrays in c, because the foreign export interface does not call
functions that free memory, like free or LocalFree.

>That's about it for now. Thanks for the interesting tool. And kudos 
>on the Clean book, which is one of the best intro functional 
>programming texts that I've seen.

Thank you.

>All of this is running with Clean 2.2 under Window XP on a Core Duo processor.

Kind regards,

John van Groningen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.science.ru.nl/pipermail/clean-list/attachments/20070227/aeb0795d/attachment.html


More information about the clean-list mailing list