Skip to content

Commit

Permalink
Change code style for the XDK examples
Browse files Browse the repository at this point in the history
  • Loading branch information
cpurdy committed Jun 2, 2023
1 parent dd638f7 commit 988cec1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 30 deletions.
16 changes: 6 additions & 10 deletions xdk/src/main/resources/xdk/examples/FizzBuzz.x
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,16 @@
*
* xec FizzBuzz
*/
module FizzBuzz
{
void run()
{
module FizzBuzz {
void run() {
@Inject Console console;
for (Int x : 1..100)
{
console.print(switch (x % 3, x % 5)
{
for (Int x : 1..100) {
console.print(switch (x % 3, x % 5) {
case (0, 0): "FizzBuzz";
case (0, _): "Fizz";
case (_, 0): "Buzz";
case (_, _): x.toString();
});
}
});
}
}
}
10 changes: 4 additions & 6 deletions xdk/src/main/resources/xdk/examples/HelloClient.x
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,18 @@
*
* xec HelloClient
*/
module HelloClient
{
module HelloClient {
package web import web.xtclang.org;

@Inject Console console;

void run(String[] args=["http://localhost:8080"])
{
void run(String[] args=["http://localhost:8080"]) {
@Inject web.Client client;

String uri = args[0];
console.print($"Accessing: {uri.quoted()}");

assert String result := client.get(uri).to(String) as $"Request to {uri.quoted()} failed";
console.print($"The server returned: {result}");
}
}
}
}
15 changes: 6 additions & 9 deletions xdk/src/main/resources/xdk/examples/HelloServer.x
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@
* http://localhost:8080/
*/
@WebApp
module HelloServer
{
module HelloServer {
package crypto import crypto.xtclang.org;
package web import web.xtclang.org;
package xenia import xenia.xtclang.org;

import web.*;

void run()
{
void run() {
import crypto.KeyStore;
@Inject(opts=new KeyStore.Info(#./https.p12, "password")) KeyStore keystore;
xenia.createServer(this, "localhost", keystore, httpPort=8080, httpsPort=8090);
Expand All @@ -40,12 +38,11 @@ module HelloServer
|
|Use Ctrl-C to stop.
);
}
}

@WebService("/")
service SiteRoot
{
service SiteRoot {
@Get
String sayHello() = "Hello, World!";
}
}
}
}
8 changes: 3 additions & 5 deletions xdk/src/main/resources/xdk/examples/HelloWorld.x
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
*
* xec HelloWorld
*/
module HelloWorld
{
void run()
{
module HelloWorld {
void run() {
@Inject Console console;
console.print("Hello, World!");
}
}
}

0 comments on commit 988cec1

Please sign in to comment.