update example and Readme.org

This commit is contained in:
2025-07-31 17:49:21 +03:00
parent bc54ae6a05
commit 3e535c9517
2 changed files with 20 additions and 45 deletions

View File

@@ -45,40 +45,27 @@ but you can pass any using ~--c-compiler~ option, or by setting
~SEX_CC~ environment variable. ~SEX_CC~ environment variable.
** Example ** Example
Here is an example, demonstrating what Sex source looks like, and what An example of Sex source:
it compiles too. An avid reader also shall notice how we call Chicken
procedures in Sex source.
The Sex source:
#+begin_src #+begin_src
(include stdio.h) (include stdio.h)
(define (foo)
"Hello from Chicken code!\n")
(pub fn int main ((int argc) (char **argv)) (pub fn int main ((int argc) (char **argv))
(puts "Hello from Sex!") (puts "Hello from Sex!")
(var (array char 512) name) (var (array char 512) name)
(puts "What is your name?") (puts "What is your name?")
(scanf "%s" &name) (scanf "%s" (cast char* &name))
(printf "Hello, %s!\n" name) (printf "Hello, %s!\n" name)
(printf ,(foo)) 0)
0)
#+end_src #+end_src
The resulting C source: Compile and run:
#+begin_src #+begin_src
#include <stdio.h> ~/dev/sex $ ./sexc ./example/hello-world.sex -o hello-world
~/dev/sex $ ./hello-world
int main (int argc, char **argv) { Hello from Sex!
puts("Hello from Sex!"); What is your name?
char name[512]; Alex
puts("What is your name?"); Hello, Alex!
scanf("%s", &name);
printf("Hello, %s!\n", name);
printf("Hello from Chicken code!\n");
return 0;
}
#+end_src #+end_src
* Features * Features
@@ -86,28 +73,12 @@ int main (int argc, char **argv) {
Just ~(include "Your/Favourite/Library.h")~ and use it as you would Just ~(include "Your/Favourite/Library.h")~ and use it as you would
have is C. have is C.
** Auto unkebabification
For hardcore fans of traditional Lisp naming convention, For hardcore fans of traditional Lisp naming convention,
Sex offers automatic unkebabification of all symbols, i.e. no more Sex offers automatic unkebabification of all symbols, i.e. no more
ugly ~GL_ARRAY_BUFFER~ s in your code, they may be written in their ugly ~GL_ARRAY_BUFFER~ s in your code, they may be written in their
proper form: ~GL-ARRAY-BUFFER~. proper form: ~GL-ARRAY-BUFFER~.
** Auto typedef for structs
Probably harmless idk. Example:
#+begin_src
(struct foo
((float a)
(int b)))
#+end_src
expands to
#+begin_src
typedef struct foo foo;
struct foo {
float a;
int b;
};
#+end_src
** Modules ** Modules
Each source file is a module. Module can provide public interface and Each source file is a module. Module can provide public interface and
be imported by using ~(import path/to/module)~ expression. Module be imported by using ~(import path/to/module)~ expression. Module

View File

@@ -1,5 +1,9 @@
(include stdio.h) (include stdio.h)
(pub fn int main () (pub fn int main ((int argc) (char **argv))
(puts "Hello from Sex!") (puts "Hello from Sex!")
(var (array char 512) name)
(puts "What is your name?")
(scanf "%s" (cast char* &name))
(printf "Hello, %s!\n" name)
0) 0)