Skip to content

Commit

Permalink
remove-foo-bar-quux-batz-kek-references
Browse files Browse the repository at this point in the history
  • Loading branch information
inoas authored and lpil committed Jul 30, 2024
1 parent 415b7c3 commit b638494
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 56 deletions.
15 changes: 7 additions & 8 deletions cheatsheets/gleam-for-elixir-users.md
Original file line number Diff line number Diff line change
Expand Up @@ -428,15 +428,14 @@ fn main() {
}
```


## Blocks

#### Elixir

In Elixir expressions can be grouped using `do` and `end`.

```elixir
defmodule Foo do
defmodule Wibble do
def main() do
x = do
print(1)
Expand Down Expand Up @@ -629,15 +628,15 @@ let name = person.name
In Elixir, the `defmodule` keyword allows to create a module. Multiple modules can be defined in a single file.

```elixir
defmodule Foo do
defmodule Wibble do
def identity(x) do
x
end
end

defmodule Bar do
defmodule Wobble do
def main(x) do
Foo.identity(1)
Wibble.identity(1)
end
end
```
Expand All @@ -647,17 +646,17 @@ end
Gleam's file is a module and named by the file name (and its directory path). Since there is no special syntax to create a module, there can be only one module in a file.

```gleam
// in file foo.gleam
// in file Wibble.gleam
pub fn identity(x) {
x
}
```

```gleam
// in file main.gleam
import foo // if foo was in a folder called `lib` the import would be `lib/foo`
import Wibble // if Wibble was in a folder called `lib` the import would be `lib/Wibble`
pub fn main() {
foo.identity(1)
Wibble.identity(1)
}
```

Expand Down
76 changes: 38 additions & 38 deletions cheatsheets/gleam-for-php-users.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,20 @@ there can be `docblocks` like so:
/**
* a very special trait.
*/
trait Foo {}
trait Wibble {}

/**
* A Bar class
* A Wabble class
*/
class Bar {}
class Wabble {}

/**
* A quux function.
* A wubble function.
*
* @var string $str String passed to quux
* @var string $str String passed to wubble
* @return string An unprocessed string
*/
function quux(string $str) : string { return $str; }
function wubble(string $str) : string { return $str; }
```

Documentation blocks (docblocks) are extracted into generated API
Expand Down Expand Up @@ -153,8 +153,8 @@ variable names.
// $a == 1
// $b == 2

[1 => $idx2] = ['foo', 'bar', 'quux'];
// $idx2 == 'bar'
[1 => $idx2] = ['wibble', 'wabble', 'wubble'];
// $idx2 == 'wabble'

["profession" => $job] = ['name' => 'Joe', 'profession' => 'hacker'];
// $job == 'hacker'
Expand Down Expand Up @@ -192,8 +192,8 @@ These hints will mainly be used to inform static analysis tools like IDEs,
linters, etc.

```php
class Foo {
private ?string $bar;
class Wibble {
private ?string $wabble;
}
```

Expand All @@ -205,7 +205,7 @@ and each element can be of a different type:
```php
$someList = [1, 2, 3];
$someTuple = [1, "a", true];
$someMap = [0 => 1, "foo" => "bar", true => false];
$someMap = [0 => 1, "wibble" => "wabble", true => false];
```

Single variables cannot be type-annotated unless they are `class` or `trait`
Expand All @@ -217,7 +217,7 @@ In Gleam type annotations can optionally be given when binding variables.

```gleam
let some_list: List(Int) = [1, 2, 3]
let some_string: String = "Foo"
let some_string: String = "Wibble"
```

Gleam will check the type annotation to ensure that it matches the type of the
Expand Down Expand Up @@ -304,22 +304,22 @@ private module-level functions.
However at class level, all properties are public, by default.

```php
class Foo {
static $bar = 5;
private $quux = 6;
class Wibble {
static $wabble = 5;
private $wubble = 6;

static function batz() {
static function wobble() {
return "Hello Joe!";
}

private static function kek() {
private static function webble() {
return "Hello Rasmus!";
}
}
echo Foo::$bar; // 5
echo Foo::$quux; // Error
echo Foo::batz(); // "Hello Joe"
echo Foo::kek(); // Error
echo Wibble::$wabble; // 5
echo Wibble::$wubble; // Error
echo Wibble::wobble(); // "Hello Joe"
echo Wibble::webble(); // Error
```

#### Gleam
Expand Down Expand Up @@ -529,9 +529,9 @@ are fully type checked.
- PHP operators are short-circuiting as in Gleam.
- Chains and pipes:
- In PHP chaining is usually done by constructing class methods that return
an object: `$foo->bar(1)->quux(2)` means `bar(1)` is called as a method
of `$foo` and then `quux()` is called as a method of the return value
(object) of the `bar(1)` call. The objects in this chain usually
an object: `$wibble->wabble(1)->wubble(2)` means `wabble(1)` is called as a method
of `$wibble` and then `wubble()` is called as a method of the return value
(object) of the `wabble(1)` call. The objects in this chain usually
mutate to keep the changed state and carry it forward in the chain.
- In contrast in Gleam piping, no objects are being returned but mere data
is pushed from left to right much like in unix tooling.
Expand Down Expand Up @@ -578,7 +578,7 @@ Blocks are declared via curly braces.
```php
function a_func() {
// A block starts here
if ($foo) {
if ($wibble) {
// A block here
} else {
// A block here
Expand Down Expand Up @@ -1125,7 +1125,7 @@ two different types they must be wrapped in a new custom type.
#### PHP

```php
class Foo {
class Wibble {
public ?string $aStringOrNull;
}
```
Expand Down Expand Up @@ -1229,14 +1229,14 @@ such declaration per file.
Using PHP namespaces, these can be placed in a registry that does not need to
map to the source code file system hierarchy, but by convention should.

In `src/Foo/Bar.php`:
In `src/Wibble/Wabble.php`:

```php
// Anything declared in this file will be inside namespace Foo
namespace Foo;
// Anything declared in this file will be inside namespace Wibble
namespace Wibble;

// Creation of (static) class Bar in Foo, thus as Foo/Bar
class Bar {
// Creation of (static) class Wabble in Wibble, thus as Wibble/Wabble
class Wabble {
public static function identity($x) {
return $x;
}
Expand All @@ -1248,9 +1248,9 @@ Making the static class available in the local scope and calling the function

```php
// After auto-loading has happened
use Foo\Bar;
use Wibble\Wabble;

Bar::identity(1); // 1
Wabble::identity(1); // 1
```

### Gleam
Expand All @@ -1267,24 +1267,24 @@ Since there is no special syntax to create a module, there can be only one
module in a file and since there is no way name the module the filename
always matches the module name which keeps things simple and transparent.

In `/src/foo/bar.gleam`:
In `/src/wibble/wabble.gleam`:

```gleam
// Creation of module function identity
// in module bar
// in module wabble
pub fn identity(x) {
x
}
```

Importing the `bar` module and calling a module function:
Importing the `wabble` module and calling a module function:

```gleam
// In src/main.gleam
import foo/bar // if foo was in a directory called `lib` the import would be `lib/foo/bar`.
import wibble/wabble // if wibble was in a directory called `lib` the import would be `lib/wibble/wabble`.
pub fn main() {
bar.identity(1) // 1
wabble.identity(1) // 1
}
```

Expand Down
6 changes: 3 additions & 3 deletions cheatsheets/gleam-for-python-users.md
Original file line number Diff line number Diff line change
Expand Up @@ -851,17 +851,17 @@ There is no special syntax to define modules as files are modules in Python
Gleam's file is a module and named by the file name (and its directory path). Since there is no special syntax to create a module, there can be only one module in a file.

```gleam
// in file foo.gleam
// in file wibble.gleam
pub fn identity(x) {
x
}
```

```gleam
// in file main.gleam
import foo // if foo was in a folder called `lib` the import would be `lib/foo`
import wibble // if wibble was in a folder called `lib` the import would be `lib/wibble`
pub fn main() {
foo.identity(1)
wibble.identity(1)
}
```

Expand Down
14 changes: 7 additions & 7 deletions cheatsheets/gleam-for-rust-users.md
Original file line number Diff line number Diff line change
Expand Up @@ -584,17 +584,17 @@ In Rust, the `mod` keyword allows to create a module. Multiple modules can be de
Rust uses the `use` keyword to import modules, and the `::` operator to access properties and functions inside.

```rust
mod foo {
mod wibble {
pub fn identity(x: u64) -> u64 {
x
}
}

mod bar {
use super::foo;
mod wobble {
use super::wibble;

fn main() {
foo::identity(1);
wibble::identity(1);
}
}
```
Expand All @@ -606,16 +606,16 @@ In Gleam, each file is a module, named by the file name (and its directory path)
Gleam uses the `import` keyword to import modules, and the dot `.` operator to access properties and functions inside.

```gleam
//// In module foo.gleam
//// In module wibble.gleam
pub fn identity(x) {
x
}
```

```gleam
// in module main.gleam
import foo // if foo was in a folder called `lib` the import would be `lib/foo`
import wibble // if wibble was in a folder called `lib` the import would be `lib/wibble`
pub fn main() {
foo.identity(1)
wibble.identity(1)
}
```

0 comments on commit b638494

Please sign in to comment.