Re: how to know the filename, line number at the function called ?
Also I can't find it in online help, and it causes syntax error. so far, this example cannot seems to work and compiler complains it cannot recognize 'tokens'. Yes, that example was incorrect. Here are macros that return the current filename (as a String) and line number (as an int). I tested these and they work. For example: {output {this-file}, :, {this-line}} Remember that macros (like all macros) need to go in a different package than where they are called. {import * from CURL.LANGUAGE.SOURCE} {define-macro public {this-file ?empty:{pattern}} {return {Literal {if-non-null url = empty.url then url.name else [unknown file] } } } } {define-macro public {this-line ?empty:{pattern}} let line:int = {empty.location-to-line-column empty.start-location} {return {Literal line}} } *** To unsubscribe from this list, send a mail to: mailto:[EMAIL PROTECTED] To contact a human list administrator, send a mail to: mailto:[EMAIL PROTECTED] To recieve a list of other options for this list, send a mail to: mailto:[EMAIL PROTECTED]
Re: Is there encode library with Curl ?
takanobu I think it's the best and cool to use some encoding takanobu algorythms for those two elements(create hash value and key takanobu predication), but I can't find any libraries such as md5 takanobu and so on. You can compute SHA-1 hashes, which serve a similar purpose to MD5, using the SHA-1-Digester class. But normally no one uses a hashing algorithm this complicated for hash tables. HashTable-of only want a 32-bit int hash, not a full 160-bit very complicated and cryptographically strong hash like SHA-1. Usually you use a much simpler and faster function. For example, if you had a class MyClass with two String fields, and you wanted to map those to ints, your hash table might look like this: {define-proc public {MyClass-hash c:MyClass}:int {return {value-hash c.string1} * 37 + {value-hash c.string2}} } {define-proc public {MyClass-equal c1:MyClass, c2:MyClass}:bool {return c1.string1 == c2.string1 and c1.string2 == c2.string2} } {let public constant MyClassHashTable:Type = {HashTable-of MyClass, int, key-hash-proc = MyClass-hash, key-equality-proc = MyClass-equal } } In general you can use value-hash to access Curl's default hash function for something. For most objects, this hash is just based on its identity (i.e. their address). But for a few classes that override what == does, such as String, it actually looks at the contents of the object (for String it mathematically combines the characters of the String in a certain way to produce an int). What's important when choosing a hash function is that if two objects are equal, they must have the same hash. It is OK (and unavoidable) for two objects that are not equal to have the same hash (a hash collision). The less often this happens, the better a hash function you have chosen. -Mat *** To unsubscribe from this list, send a mail to: mailto:[EMAIL PROTECTED] To contact a human list administrator, send a mail to: mailto:[EMAIL PROTECTED] To recieve a list of other options for this list, send a mail to: mailto:[EMAIL PROTECTED]
Re: about syntax error
Like C++, isn't the instance of bbb temporaly created at constructor of aaa, then destroyed after the construction? No. Curl is a garbage-collected language, like Java and C#. Objects are only freed when there are no more pointers to them anywhere. Garbage collection loops through all the objects that have been allocated, finds the ones that are not reachable any more, and frees them automatically. You do not need to call garbage-collect yourself; the system will automatically call it for you when it needs more memory. In Curl, you just allocate objects and let the system worry about reclaiming the memory you are not using any more. This is much more convenient than C, where you have to manage memory yourself, or C++ where you have to worry about reference counting, copy constructors, etc. -Mat *** To unsubscribe from this list, send a mail to: mailto:[EMAIL PROTECTED] To contact a human list administrator, send a mail to: mailto:[EMAIL PROTECTED] To recieve a list of other options for this list, send a mail to: mailto:[EMAIL PROTECTED]
Re: about syntax error
{constructor public {default b:bbb} set fnc = {proc {}:bool {return {bbb.def}}} } Also, unlike C++, when you access fields on 'self' you must say so explicitly. So you probably want this: {constructor public {default b:bbb} set self.fnc = {proc {}:bool {return {bbb.def}}} } -Mat *** To unsubscribe from this list, send a mail to: mailto:[EMAIL PROTECTED] To contact a human list administrator, send a mail to: mailto:[EMAIL PROTECTED] To recieve a list of other options for this list, send a mail to: mailto:[EMAIL PROTECTED]
Re: BIG List/Set of unique elements
curl == Friedger [EMAIL PROTECTED] writes: What would be the most efficient data structure with respect to speed? There is 1GB ram available. I assume you main operation is checking for set membership? I would use {Set-of String}. Is it efficient to insert an element abc to a set of strings containing 134.999 elements? Yes, our container classes are all quite scalable. Set.member? and Set.insert are O(1) (amortized). The size of the Set's representation doubles when it get gets too full (as does Array's, HashTable's, etc). So a specific insert might be slow if it has to reallocate the underlying arrays, but if you do the math it's still O(1) on average, this this happens less and less often as the size gets larger. If you know the exact size the Set will be, it can be useful to use the 'efficient-size' keyword argument when you create it. If your set of strings were fixed and set membership were the critical operation, you could investigate perfect hash algorithms (sorry, no help for you in our API), but I seriously doubt it's worth the effort. -Mat *** To unsubscribe from this list, send a mail to: mailto:[EMAIL PROTECTED] To contact a human list administrator, send a mail to: mailto:[EMAIL PROTECTED] To recieve a list of other options for this list, send a mail to: mailto:[EMAIL PROTECTED]
Re: Since OS X is linux-like...
know_mystery == Know Mystery [EMAIL PROTECTED] writes: know_mystery Hello All - Is anyone working on a version of Curl that know_mystery will run on Mac? know_mystery OS X is very linux-like, and so i wonder how difficult know_mystery to get it to work on that platform. That's a good question. A few years ago we did some exploratory work on a Mac port, eventually getting one of our low-level executables working (but no JIT compiler or graphics). As you suggest, OS X supports proper threading and countless unix APIs which make the job much easier. However, the graphics system and CPU are very different, among other things, so this port would still require a great deal of work to get into shippable state. Thus far it has not been a priority compared to numerous other projects. That said, we have architected our system from the ground up to support other platforms cleanly (in fact, the original MIT version of Curl also ran on Sun SparcStations!) And right now we are actively working to improve the performance and portability of our JIT compiler, so targeting the Mac's PowerPC CPU would become easier should we decide to invest the resources. You won't see a Mac port any time soon, but you might yet see one if/when a solid business case exists for it. -Mat *** To unsubscribe from this list, send a mail to: mailto:[EMAIL PROTECTED] To contact a human list administrator, send a mail to: mailto:[EMAIL PROTECTED] To recieve a list of other options for this list, send a mail to: mailto:[EMAIL PROTECTED]
Re: Marshal array
curl == Friedger [EMAIL PROTECTED] writes: curl Hi, I would like to (remote-)marshal an array of basic curl types(String, int, ..). curl How would I do that? How does the persistent data do it? Persistent data uses a powerful serialization mechanism much like Java's, but sadly it is not public. We'll look into making a convenient serialization mechanism public in the next major release (4.0?), although I can't guarantee it will make the cut. In the meantime you pretty much have to create your own serializer, using marshaling, type-switch and some new byte tags for what follows next in the byte stream. You can then create input and output streams of 'any' wrapped around byte streams. Marshaling out an array would look something like: {serialize-out stream, SerializeTag.Array-of-any} {serialize-out stream, array.size} {for x in array do {serialize-out stream, x} } -Mat *** To unsubscribe from this list, send a mail to: mailto:[EMAIL PROTECTED] To contact a human list administrator, send a mail to: mailto:[EMAIL PROTECTED] To recieve a list of other options for this list, send a mail to: mailto:[EMAIL PROTECTED]
Re: Defining custom type aliases
leiflists == Leif Mortenson [EMAIL PROTECTED] writes: The Curl languages provides a number of Array-of aliases, like ByteArray which maps to {Array-of byte} I have a class, MyClass, for which I would like to do the same. I tried the following just before my class definition: let public constant MyClassArray:ClassType = {Array-of MyClass} {define-class public MyClass field private m_children:MyClassArray etc When I try to load this class, I get the following error: Invalid type expression 'MyClassArray'. Sometimes circular type references like this aren't allowed when they should be, because the alias depends on the class and the class depends on the alias. We are working on fixing this. But in the meantime, if you put your 'let' after the 'define-class' it should work. Sometimes, because of this bug, you may find you can't always use your handy alias inside the class that the alias depends on, but you can use it everywhere else. Also, I recommend always using curly braces around top-level 'let' and 'set' so if such code goes into an applet they don't just get silently displayed as raw text. I assume that's not the cause of the problem here, because I was able to reproduce it. -Mat *** To unsubscribe from this list, send a mail to: mailto:[EMAIL PROTECTED] To contact a human list administrator, send a mail to: mailto:[EMAIL PROTECTED] To recieve a list of other options for this list, send a mail to: mailto:[EMAIL PROTECTED]
Re: Escaping strings that are inserted into MySQL
chris == Chris Banford [EMAIL PROTECTED] writes: chris After a bit more examination, I see that once the Strings are chris input into the database correctly, that they are being chris returned with the escape characters removed. So this means I chris just need an easy way to replace the below stuff in a chris [possibly large] string. -Chris Since you don't care about escaping speed, the simplest technique is just a straightforward 'switch' in a loop like this: {define-proc public {escapify-for-mysql s:String}:String || Make a StringBuf, assume there's not much escaping needed. let buf:StringBuf = {StringBuf efficient-size = s.size + 10} {for c in s do {switch c case '\u' do {buf.concat |\0|} case '\u0008' do {buf.concat |\b|} case '\u001A' do {buf.concat |\z|} case '\n' do {buf.concat |\n|} case '\r' do {buf.concat |\r|} case '\t' do {buf.concat |\t|} case '\'', '\', '\\', '%', '_' do {buf.append '\\'} {buf.append c} else || No escaping needed. {buf.append c} } } {if buf == s then || Just return original String rather than making a new one. || This is a fairly common case. {return s} else {return {buf.to-String}} } } There are numerous ways to optimize this, but this sounds adequate for your needs. -Mat *** To unsubscribe from this list, send a mail to: mailto:[EMAIL PROTECTED] To contact a human list administrator, send a mail to: mailto:[EMAIL PROTECTED] To recieve a list of other options for this list, send a mail to: mailto:[EMAIL PROTECTED]
Re: Escaping strings that are inserted into MySQL
rhh == Bert Halstead [EMAIL PROTECTED] writes: rhh I don't see any built-in method in the StringBuf API that, in rhh one operation, appends a specified substring from another String rhh to the StringBuf Actually StringBuf.write-one-string (inherited from TextOutputStream) does exactly this. -Mat *** To unsubscribe from this list, send a mail to: mailto:[EMAIL PROTECTED] To contact a human list administrator, send a mail to: mailto:[EMAIL PROTECTED] To recieve a list of other options for this list, send a mail to: mailto:[EMAIL PROTECTED]
Re: Pixmap from FillPattern
I'm trying to create a new Pixmap from a FillPattern. When I run the following, I'm getting an ArrayBoundsException: Array index out of bounds. error. let new-image:Pixmap = {my-fillpattern.to-Pixmap} Any ideas what I'm doing wrong? If you can post a small but complete program that reproduces the problem, I'll take a look. -Mat *** To unsubscribe from this list, send a mail to: mailto:[EMAIL PROTECTED] To contact a human list administrator, send a mail to: mailto:[EMAIL PROTECTED] To recieve a list of other options for this list, send a mail to: mailto:[EMAIL PROTECTED]