language-features

Why is this Option transformed to a String? [Scala]

I'm still a Scala noob, and this confuses me: import java.util.regex._ object NumberMatcher { def apply(x:String):Boolean = { val pat = Pattern.compile("\\d+") val matcher = pat.matcher(x) return matcher.find } def unapply(x:String):Option[String] = { val pat = Pattern.compile("\\d+") val matcher = pat.matche...

Where can I find documentation for Scala's delayed function calls?

I saw a delayed example in David Pollak's "Beginning Scala". I tried to adapt that, by trial and error. Here's what I have: def sayhello() = { println("hello") } def delaying(t: => Unit):Unit = { println("before call") t println("after call") } delaying(sayhello()) How would you delay a function/method that takes parameters?...

Need some help with Scala's instance variables

Assume this Java code: public class A { public A(String g) { x += g.length(); } private int x = 0; } If I create an instance of A, like this: A a = new A("geo"); after this call, the value of x will be 3. What am I doing wrong in my Scala code? class A(val g:String) { x += g.length var x:Int = 0 } object x ext...

Does it exists a shorter if statement in PHP?

Is it possible to rewrite this to be shorter somehow? if (isset($_POST['pic_action'])){ $pic_action=$_POST['pic_action']; } else { $pic_action=0; } I have seen it somewhere but forgot... :/ BTW, please explain your code also if you like! Thanks ...

PHP Language System with no user registration

i want to make my site available in several languages, but im not going to use user registration so how can i make a language system? searched for a cookie language system tutorial but didnt found anything if you have any other suggestion please share, and i cant use modrewrite ...

Data structures- what determines inclusion in language library?

With an assignment dealing with access control lists, it was required to construct a doubly-linked list first, as Java doesn't include that in the SUN API. I can understand if the professor wanted us to create the Doubly Linked List from scratch to understand how it works (like writing a sort program vs using the baked in methods), but w...

How to Correctly Use Lists in R?

Brief background: Many (most?) modern programming languages in widespread use have at least a handful of ADTs in common, in particular, string (a (sequence comprised of characters), list (an ordered collection of values), and a map-based type (an unordered key-value store). In the R, the first two are implemented as 'character' and 'vect...

Is there any Scala feature that allows you to call a method whose name is stored in a string?

Assuming you have a string containing the name of a method, an object that supports that method and some arguments, is there some language feature that allows you to call that dinamically? Kind of like Ruby's send. ...

Is There a Syntax Shortcut for Multiple Initialization in C#?

Is there a way to do this: valueType x = 1, y = 1, z = 1; with less characters? e.g. When I have a large amount of state to initialize to the same starting value. Thanks! ...

.net : Why/when and how to Use the new features of .net that i am learning

i've been programming in C#/asp.net for some years now (mostly basic programs and websites),and lately i started reading about .net features and programming techniques like Linq,lambda expressions,Generics and such.. Features List: Object Initializers Extension Methods Anonymous Types Generics Lambda Expressions LINQ What i am trying...

Java ?: operator in vb.net

Is there a ?: operator equivalent in .net? eg in java I can do: retParts[0] = (emailParts.length > 0) ? emailParts[0] : ""; rather than if (emailParts.length > 0) { retParts[0] = emailParts[0]; } else { retParts[0] = ""; } I'd like to be able to do similar in VB.NET. ...

Is there, or is there ever going to be, a conditional operator in Delphi?

I kept my hands off Delphi for too long, I guess; busied myself with Java and PHP a lot over the last couple of years. Now, when I got back to doing a little Delphi job, I realised I really miss the conditional operator which is supported by both Java and PHP. On how many places would you find lines like these in your Delphi programs? ...

Which languages have readily available safe evaluation environments?

I'm speaking specifically of something like the PLT Scheme make-evaluator. It will run scheme code, but under certain conditions: It only uses a definable amount of memory, and will quit execution if the script needs more It behaves similarly with time It restricts all IO except for what I specifically allow in the code Is anyone ...

Alternative way of implementing a groupBy method in Scala?

I've come up with this implementation of groupBy: object Whatever { def groupBy[T](in:Seq[T],p:T=>Boolean) : Map[Boolean,List[T]] = { var result = Map[Boolean,List[T]]() in.foreach(i => { val res = p(i) var existing = List[T]() // how else could I declare the reference here? If I write var exi...

C#: enforceable way of signifying a method is there as part of interface

Is there a way in C# to mark a method as being part of a class to satisfy an interface that the class implements? I find myself wondering sometimes when digging in a class's code why some methods are there but then, when I try to remove one since it isn't in use, I see it's necessary in order for the class to implement some interface. ...

Events on PHP. Is it possible?

I'm coming from the C# world and has just started doing a little PHP coding, so I was wondering if it is possible to use events on PHP, or if it is planned to include this feature in a future release. If you have a way to simulate it, different than this, it would be very appreciated, thanks. ...

How does one define and describe these different points in time?

Background: Eldridge asked me to explain what the difference is between the difference phases of time when it comes to writing and deploying code. He wants to know: 1) what is the difference between: 1) design time; 2) compile time; 3) run-time? 2) what are specific examples of things a programmer would not be able to hard-wire into ...

Do you think F#'s async workflows will be introduced in C# in the future?

First of all, I apologize because of my foolish question, I really don't know much about F#. But I know that it makes thread handling significantly easier. However, seeing the language construct someone might wonder why C# should miss the coolness that is asynchronous workflows? What theoretical limitation does C# have that prevents the ...

Why can this kind of statement work in PHP?

$user->Phonenumbers[]->phonenumber = '123 123'; $user->Phonenumbers[]->phonenumber = '456 123'; $user->Phonenumbers[]->phonenumber = '123 777'; I've never seen this kind of syntax EDIT This seems more probably a feature,do you guys know how can I implement a feature like this? ...

Are there any disadvantages of using C# 3.0 features?

I like C# 3.0 features especially lambda expressions, auto implemented properties or in suitable cases also implicitly typed local variables (var keyword), but when my boss revealed that I am using them, he asked me not to use any C# 3.0 features in work. I was told that these features are not standard and confusing for most developers a...