Skip to content

Commit 93e53a0

Browse files
authored
Merge pull request #116 from phel-lang/docs/improve-getting-started
Simplify getting started page
2 parents 247268c + feb0598 commit 93e53a0

File tree

3 files changed

+72
-73
lines changed

3 files changed

+72
-73
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ zola serve # build & serve
3131

3232
```bash
3333
zola build # build & publish
34-
```
34+
```

content/_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ docker run -it --rm phellang/repl
6868

6969
## Get Started with Phel in Minutes
7070

71-
All you need is [PHP >=8.2](https://www.php.net/) and [Composer](https://getcomposer.org/).
71+
All you need is [PHP >=8.2](https://www.php.net/) and [Composer](https://getcomposer.org/).
7272

7373
> Follow our [Getting Started Guide](/documentation/getting-started) to build and run your first Phel program today.
7474
Lines changed: 70 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,132 +1,131 @@
11
+++
2-
title = "Getting started"
2+
title = "Getting Started"
33
weight = 1
44
+++
55

66
## Requirements
77

8-
Phel requires PHP 8.2 or higher and [Composer](https://getcomposer.org/).
8+
- PHP 8.2+
9+
- [Composer](https://getcomposer.org/)
910

10-
## Quick start with a scaffolding template
11+
## Quick Start
1112

12-
To get started right away, you can create a new Phel commandline project via Composer's `create-project` command:
13+
Scaffold a new project:
1314

1415
```bash
1516
composer create-project --stability dev phel-lang/cli-skeleton example-app
16-
```
17-
18-
Once the project has been created, start the REPL (read-evaluate-print loop) to try Phel.
19-
20-
```bash
2117
cd example-app
2218
composer repl
2319
```
2420

25-
> Alternatively to the [phel-lang/cli-skeleton](https://github.com/phel-lang/cli-skeleton), you can also use [phel-lang/web-skeleton](https://github.com/phel-lang/web-skeleton) for a web project. More information can be found in the [README](https://packagist.org/packages/phel-lang/cli-skeleton) of the project.
26-
27-
28-
## Manually initialize a new project using Composer
21+
> For web projects: [web-skeleton](https://github.com/phel-lang/web-skeleton)
2922
30-
The easiest way to get started is by setting up a new Composer project. First, create a new directory and initialize a new Composer project.
23+
## Manual Setup
3124

3225
```bash
33-
mkdir hello-world
34-
cd hello-world
26+
mkdir hello-world && cd hello-world
3527
composer init
36-
```
37-
38-
Next, require Phel as a dependency.
39-
40-
```bash
4128
composer require phel-lang/phel-lang
29+
mkdir src
4230
```
4331

44-
> Optionally, you can create `phel-config.php` at the root of the project:
45-
> ```php
46-
> <?php
47-
>
48-
> return (new \Phel\Config\PhelConfig())
49-
> ->setSrcDirs(['src']);
50-
> ```
51-
> Read the docs to see all available [configuration](/documentation/configuration) options for Phel.
32+
Optional config (`phel-config.php`):
5233

53-
Then, create a new directory `src` with a file `main.phel` inside this directory.
54-
55-
```bash
56-
mkdir src
34+
```php
35+
<?php
36+
return (new \Phel\Config\PhelConfig())
37+
->setSrcDirs(['src']);
5738
```
5839

59-
The file `main.phel` contains the actual code of the project. It defines the namespace and prints "Hello, World!".
40+
Sample Phel file (`src/main.phel`):
6041

6142
```phel
62-
# inside `src/main.phel`
6343
(ns hello-world\main)
64-
6544
(println "Hello, World!")
6645
```
6746

68-
## Running the code
47+
## Run Code
48+
49+
**From CLI:**
6950

70-
There are two ways to run the code: from the command line and with a PHP Server.
51+
```bash
52+
vendor/bin/phel run src/main.phel
53+
```
7154

72-
### From the Command line
55+
**With PHP Server:**
7356

74-
Code can be executed from the command line by calling the `vendor/bin/phel run` command, followed by the file path or namespace:
57+
```php
58+
<?php
59+
require __DIR__ . '/../vendor/autoload.php';
60+
\Phel\Phel::run(__DIR__ . '/../', 'hello-world\\main');
61+
```
7562

7663
```bash
77-
vendor/bin/phel run src/main.phel
78-
# or
79-
vendor/bin/phel run hello-world\\main
80-
# or
81-
vendor/bin/phel run "hello-world\main"
64+
php -S localhost:8000 ./src/index.php
8265
```
8366

84-
The output will be:
67+
> 📘 [More on running code](/documentation/cli-commands#run-a-script)
68+
69+
## REPL
8570

71+
```bash
72+
vendor/bin/phel repl
8673
```
87-
Hello, World!
74+
75+
Try:
76+
77+
```phel
78+
(def name "World")
79+
(println "Hello" name)
8880
```
8981

90-
### With a PHP Server
82+
> 📘 [More on REPL](/documentation/repl)
9183
92-
> Check the [web-skeleton project on GitHub](https://github.com/phel-lang/web-skeleton).
84+
## Debugging
9385

94-
The file `index.php` will be executed by the PHP Server. It initializes the Phel Runtime and loads the namespace from the `main.phel` file described above, to start the application.
86+
```phel
87+
(php/dump (+ 40 2))
88+
```
89+
90+
Enable temp files in `phel-config-local.php`:
9591

9692
```php
97-
// src/index.php
9893
<?php
94+
return (require __DIR__ . '/phel-config.php')
95+
->setKeepGeneratedTempFiles(true);
96+
```
9997

100-
use Phel\Phel;
101-
102-
$projectRootDir = __DIR__ . '/../';
98+
> 📘 [More on debugging](/documentation/debug)
10399
104-
require $projectRootDir . 'vendor/autoload.php';
100+
## Build & Deploy
105101

106-
Phel::run($projectRootDir, 'hello-world\\main');
102+
```bash
103+
vendor/bin/phel build
104+
php out/index.php
107105
```
108106

109-
The PHP Server can now be started.
107+
> 📘 [More on build](/documentation/cli-commands/#build-the-project)
108+
109+
## Testing
110110

111111
```bash
112-
# Start server
113-
php -S localhost:8000 ./src/index.php
112+
vendor/bin/phel test --filter foo
114113
```
115114

116-
In the browser, the URL `http://localhost:8000` will now print "Hello, World!".
117-
118-
> When using a web server, consider building the project to avoid compilation time for each request; so PHP will run the transpiled PHP code instead to gain performance. See more [Buid the project](/documentation/cli-commands/#build-the-project).
115+
> 📘 [More on testing](/documentation/testing)
119116
120-
## Launch the REPL
117+
## Handy Macros
121118

122-
To try Phel you can run a REPL by executing the `./vendor/bin/phel repl` command.
119+
```phel
120+
(when condition (println "if true"))
121+
(-> {:name "Phel"} (:name) (str "Lang"))
122+
```
123123

124-
> Read more about the [REPL](/documentation/repl) in its own chapter.
124+
> 📘 [More on macros](/documentation/macros)
125125
126-
## Editor support
126+
## Editor Support
127127

128-
Phel comes with basic support for <a href="https://github.com/phel-lang/phel-vs-code-extension" target="_blank">
129-
VSCode</a>, <a href="https://github.com/phel-lang/phel-phpstorm-syntax" target="_blank">PhpStorm</a>, a
130-
<a href="https://codeberg.org/mmontone/interactive-lang-tools/src/branch/master/backends/phel" target="_blank">
131-
Emacs mode with interactive capabilities</a> and a <a href="https://github.com/danirod/phel.vim" target="_blank">Vim
132-
plugin</a> in the making.
128+
- [VSCode](https://github.com/phel-lang/phel-vs-code-extension)
129+
- [PhpStorm](https://github.com/phel-lang/phel-phpstorm-syntax)
130+
- [Emacs](https://codeberg.org/mmontone/interactive-lang-tools)
131+
- [Vim](https://github.com/danirod/phel.vim)

0 commit comments

Comments
 (0)