Someone just told me that implementing an interface in F# is less vebose than in Ceylon. Let's see if that's true. Pick an example given on MSDN. (Yes, I know it's silly to make such trivial comparisons.)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ceylon.locale { | |
systemLocale | |
} | |
import ceylon.time { | |
today, | |
date | |
} | |
import ceylon.time.base { | |
monthOf | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"Parse a properties file." | |
void parsePropertiesFile(String textContent, | |
void handleEntry(String key, String text)) { | |
value lines = textContent.lines.iterator(); | |
while (!is Finished rawline = lines.next()) { | |
value builder = StringBuilder(); | |
builder.append(rawline); | |
variable value lastline = rawline; | |
while (lastline.endsWith("\\"), //line continuation | |
!is Finished nextline = lines.next()) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shared void balancedBrackets() { | |
value nextRandom = random(); | |
for (length in 1..10) { | |
value text = generate(nextRandom, length); | |
print("``text.padTrailing(20)`` - ``if (balanced(text)) then "OK" else "NOT OK"``"); | |
} | |
} | |
Boolean balanced(String input) | |
=> !input |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shared void run() { | |
for (perm in permutations("ABCD").indexed) { | |
print(perm); | |
} | |
} | |
shared {Element[]*} permutations<Element> | |
(List<Element> list) | |
=> object satisfies {Element[]*} { | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shared String formatFloat( | |
"The floating point value to format." | |
Float float, | |
"The minimum number of allowed decimal places. | |
If `minDecimalPlaces<=0`, the result may have no | |
decimal point." | |
Integer minDecimalPlaces=1, | |
"The maximum number of allowed decimal places. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Gavins-New-MacBook-Pro:ceylon-dist gavin$ ant -Dbuild-against=last-release clean-ide eclipse | |
Buildfile: /Users/gavin/ceylon-dist/build.xml | |
clean-ide: | |
siblings: | |
clean: | |
clean-item: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Description Location Resource Path Type | |
Access restriction: The constructor 'CoreException(IStatus)' is not API (restriction on required library '/Users/gavin/ceylon-ide-eclipse/plugins/com.redhat.ceylon.eclipse.ui/target/repo/plugins/org.eclipse.equinox.common-3.6.200.v20130402-1505.jar') line 123 AndroidBuildHookProvider.java /com.redhat.ceylon.eclipse.android.plugin/src/com/redhat/ceylon/eclipse/android/plugin Java Problem | |
Access restriction: The constructor 'Status(int, String, int, String, Throwable)' is not API (restriction on required library '/Users/gavin/ceylon-ide-eclipse/plugins/com.redhat.ceylon.eclipse.ui/target/repo/plugins/org.eclipse.equinox.common-3.6.200.v20130402-1505.jar') line 123 AndroidBuildHookProvider.java /com.redhat.ceylon.eclipse.android.plugin/src/com/redhat/ceylon/eclipse/android/plugin Java Problem | |
Access restriction: The constructor 'Status(int, String, String, Throwable)' is not API (restriction on required library '/Users/gavin/ceylon-ide-eclipse/plugins/com.redhat.ceylon.ecl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shared Map<Key,Item> reduceByKey<Key,Item>( | |
{<Key->Item>+} stream, | |
Item accumulating(Item x, Item y)) | |
given Key satisfies Object | |
given Item satisfies Object | |
=> stream.summarize(Entry.key, | |
(Item? partial, entry) | |
=> let (_->item = entry) | |
if (exists partial) | |
then accumulating(partial, item) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Demonstrates how to do monadic-style processing of | |
optional values in Ceylon. Represents an optional | |
type by boxing non-null values as singletons, and | |
the null value as the empty sequence. Monadic | |
operations are inherited from the stream interface, | |
with the caveat that m.flatMap(f) must be written | |
as m.flatMap(lift(f)) or as m.map(f).coalesced. | |
For the record: this is not idiomatic Ceylon. In |