Aaron Harnly | 16 Apr 19:43 2007
Picon

Re: Closures: I don't want a parameter?

Thanks, Martin.

On Apr 16, 2007, at 1:35 PM, Martin Voelkle wrote:
> Maybe this is what you are looking for:
>
> scala> val unit_addnine = { () => myset + 9 }
> unit_addnine: () => scala.collection.mutable.Set[scala.Int] =  
> <function>
>
> scala> unit_addnine()
> line5: scala.collection.mutable.Set[scala.Int] = Set(9)

Yep, this is what I was hoping for -- thanks!
Now i feel foolish -- I see the description in section 6.22 of the  
Scala Reference of the use of the empty parameter list.

cheers,
aaron

Max Fritzsche | 16 Apr 19:42 2007
Picon

Re: Closures: I don't want a parameter?

Aaron Harnly wrote:
>
> But I'd rather not have that dummy parameter, obviously.
> One option is to store a reference to the object separately, and 
> supply the object as a parameter:
I can make your example only work with the { () => body}-Construct:

    val mySet = scala.collection.mutable.Set[Int]()
    val addnine = {() => mySet+=9}
    val addfour = {() => mySet+=4}
    val removenine = {() => mySet-=9}

    def printSet = Console.println(mySet.mkString("{", ", ", "}"))

    printSet // prints {}
    addnine()
    printSet // prints {9}
    addfour()
    printSet // prints {9, 4}
    removenine()
    printSet // prints {4}

I guess { => body} closures aren't allowed to be stored in variable.

    Max

Tony Morris | 16 Apr 23:10 2007
Picon

Re: While/if gotcha when translating from Java

It's bad practice (ultimately) because it involves a destructive update.
I wish Scala emitted a warning for all such operations!

I got caught out the other day converting an Iterator to a lazy list.
Since Iterator.next is destructive (sigh) and my arguments to a function
were lazy, the order of execution of it.hasNext and it.next were
unspecified. Chaos ensued. I had to explicitly enforce order of
evaluation with val declarations.

Tony Morris
http://tmorris.net/

Warren Henning wrote:
> It's bad programming practice to do that, anyway.
> 
> Scala is under no obligation to slavishly obey bad programming practices.
> 
> Warren
> 

Aaron Harnly | 16 Apr 23:34 2007
Picon

-Xgenerics and java.lang.Class

Hi all,
Today is my day for questions, it seems :)

I seem to have encountered an issue with the -Xgenerics compiler  
option, and wonder if anyone can offer some insight.

I have a snippet that defines a trait / interface that will be loaded  
by some Java code. Specifically, it's an RMI interface. (This is  
because I was being beaten in the head by Remote Actors, but that's  
another story...)

code
----
import java.rmi.{Remote,RemoteException}
trait DocExchange extends Remote {
     <at> throws(classOf[RemoteException])
    def fetchRawDocument(docid : String) : String
}

* * *
When I compile this with the -Xgenerics option enabled, I get the  
following error:
  error: type mismatch;
found   : java.lang.Class[T]
required: java.lang.Class
     <at> throws(classOf[RemoteException])
                   ^

and I can't seem to work out a way to convince the compiler that this  
will be OK.
(Continue reading)

Daniel Schregenberger | 16 Apr 23:40 2007
Picon

Illegal method name

Hi,

I've just experienced a strange thing. I have a program using ° (a
single degree sign) as an operator. It works perfect in eclipse but
gives a strange "Illegal method name" error on the console. See trace
below. I do not use a double degree sign anywhere.
This happens for both: classes compiled on the console and the
eclipse-generated classes when trying to execute them on the console.

I'm trying to narrow this down, but maybe someone has a hint on why this
is happening?

I'm on scala 2.4 final and the latest eclipse plugin.

-- Daniel

$ scala universes.formalizator.demo
java.lang.ClassFormatError: Illegal method name "°°" in class
universes/formalizator/demo$
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
        at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
(Continue reading)

Jeffery Zhang | 17 Apr 00:37 2007
Picon

source code for the standard libraries

I would like to check out the source code for the scala.actors package. I only have a non-source jar, and it doesn't come with the standard lib either. The lib that comes with my distribution (eclipse) still uses scala.concurrent .

Where would I find the latest scala standard lib source code?

-Jeffery

Warren Henning | 17 Apr 00:40 2007
Picon

Re: source code for the standard libraries

Either EPFL svn or sbaz (to get source jars), I would think.

Warren

Jeffery Zhang | 17 Apr 02:20 2007
Picon

Syntax question

Hi, I was wondering what does the A -> B syntax mean?
the context I saw this in was Map("time" -> Text(timeNow.toString)) in the Clock example from the liftweb framework.

Also, what does => B mean as a type?
I saw the following code in net.liftweb.http.S

private def initNotice[B](f: => B): B = {
    _notice.doWith(new ArrayBuffer[(NoticeType.Value, NodeSeq)])(f)
  }


David Pollak | 17 Apr 02:45 2007

Re: Syntax question

Jeffrey,

A -> B creates a Pair or Tuple2 of the two elements:
scala> 1 -> 2
line0: (scala.Int, scala.Int) = (1,2)

scala> "hello" -> 33
line1: (java.lang.String, scala.Int) = (hello,33)

=> B is a function that returns type B.

Thanks,

David

Jeffery Zhang wrote:
> Hi, I was wondering what does the A -> B syntax mean?
> the context I saw this in was Map("time" -> Text(timeNow.toString)) in 
> the Clock example from the liftweb framework.
>
> Also, what does => B mean as a type?
> I saw the following code in net.liftweb.http.S
>
> private def initNotice[B](f: => B): B = {
>     _notice.doWith(new ArrayBuffer[(NoticeType.Value, NodeSeq)])(f)
>   }
>
>

Adriaan Moors | 17 Apr 09:06 2007
Picon

Re: Illegal method name


On 16 Apr 2007, at 23:40, Daniel Schregenberger wrote:

> Hi,
>
> I've just experienced a strange thing. I have a program using ° (a
> single degree sign) as an operator. It works perfect in eclipse but
> gives a strange "Illegal method name" error on the console. See trace
> below. I do not use a double degree sign anywhere.
> This happens for both: classes compiled on the console and the
> eclipse-generated classes when trying to execute them on the console.
>
> I'm trying to narrow this down, but maybe someone has a hint on why  
> this
> is happening?
I think this is due to different JVM's enforcing different validity  
checks
We're aware of the problem (http://scala-webapps.epfl.ch/bugtracking/ 
bugs/displayItem.do?id=1046), the next release should normally  
contain a fix.

adriaan

Gmane