Implement docstrings for fn definitions #5

Closed
opened 2025-08-14 16:24:53 +02:00 by pkulev · 5 comments
pkulev commented 2025-08-14 16:24:53 +02:00 (Migrated from github.com)

For the following sex code:

(include stdio.h)

(fn void greet (char **name)
  "Greet the thing using NAME."
  (printf "Hello %s!\n" name))

(pub fn int main ((int argc) (char **argv))
  "Entry point if it was not obvious.

ARGC and ARGV enter the bar..."
  (puts "Hello from Sex!")
  (var (array char 512) name)
  (puts "What is your name?")
  (scanf "%s" (cast char* &name))
  (greet name)
  (return 0))

I would expect the following C code:

#include <stdio.h>

// Greet the thing using NAME.
static void greet (int char, int **name) {
           printf("Hello %s!\n", name);
       }

// Entry point if it was not obvious.
// ARGC and ARGV enter the bar...
int main (int argc, char **argv) {
    puts("Hello from Sex!");
    char name[512];
    puts("What is your name?");
    scanf("%s", (char*)&name);
    greet(name);
    return 0;
}
For the following sex code: ```scheme (include stdio.h) (fn void greet (char **name) "Greet the thing using NAME." (printf "Hello %s!\n" name)) (pub fn int main ((int argc) (char **argv)) "Entry point if it was not obvious. ARGC and ARGV enter the bar..." (puts "Hello from Sex!") (var (array char 512) name) (puts "What is your name?") (scanf "%s" (cast char* &name)) (greet name) (return 0)) ``` I would expect the following C code: ```c #include <stdio.h> // Greet the thing using NAME. static void greet (int char, int **name) { printf("Hello %s!\n", name); } // Entry point if it was not obvious. // ARGC and ARGV enter the bar... int main (int argc, char **argv) { puts("Hello from Sex!"); char name[512]; puts("What is your name?"); scanf("%s", (char*)&name); greet(name); return 0; } ```
alex-eg commented 2025-08-14 16:29:32 +02:00 (Migrated from github.com)

Sounds nice! I believe we already have almost all we might need for this.
The only tricky part is to print comments before the function body.

Sounds nice! I believe we already have almost all we might need for this. The only tricky part is to print comments __before__ the function body.
pkulev commented 2025-08-24 13:23:26 +02:00 (Migrated from github.com)

Also I think it can be applicable for other forms too, var, struct, union. Maybe something else? define?

Also I think it can be applicable for other forms too, **var**, **struct**, **union**. Maybe something else? **define**?
pkulev commented 2025-08-24 13:27:37 +02:00 (Migrated from github.com)

Then probably we could use some C/C++ documentation generator for native sex libraries providing .so, generated .h and autogenerated documentation ehehe

Then probably we could use some C/C++ documentation generator for native sex libraries providing .so, generated .h and autogenerated documentation ehehe
alex-eg commented 2025-08-25 10:16:58 +02:00 (Migrated from github.com)

Also I think it can be applicable for other forms too, var, struct, union. Maybe something else? define?

Sure, I think there isn't any declaration that can't be docstringed.

Then probably we could use some C/C++ documentation generator for native sex libraries providing .so, generated .h and autogenerated documentation ehehe

Yes, this also we could do, and it will save us a lot of time.

>Also I think it can be applicable for other forms too, var, struct, union. Maybe something else? define? Sure, I think there isn't any declaration that can't be docstringed. >Then probably we could use some C/C++ documentation generator for native sex libraries providing .so, generated .h and autogenerated documentation ehehe Yes, this also we could do, and it will save us a lot of time.
Collaborator

Done in #30.

Done in #30.
pkulev added the feature label 2026-09-22 22:43:53 +02:00
pkulev self-assigned this 2026-09-22 22:43:57 +02:00
Sign in to join this conversation.
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: alex-eg/sex#5