Git Product home page Git Product logo

Comments (2)

nigeltao avatar nigeltao commented on May 3, 2024

I can see the appeal of having a built-in println function or statement, but that's tricky. For example, Wuffs-the-language has not needed a string type so far (other than for error messages), or varargs, whether variant in number or in type, especially as every call argument is currently explicitly named: it's foo(a:x, b:y) not just foo(x, y).

Instead, I've been adding printfs to the generated C code. It's crude, but it suffices. That's why, in gen/c/std/*.c, there's

// Uncomment this #include for printf-debugging.
// #include <stdio.h>

If you're using the wuffs command line tool, such as wuffs test, be aware of flags like -ccompilers, -focus and -skipgen. Run wuffs test -? for some brief documentation.


As for packages outside of std, I definitely want to support that one day, but it hasn't been the highest priority thing to work on yet.

You can run wuffs-c directly, or you can fork wuffs and add your own code under std. Maybe a symlink would work, if you're just playing around and don't care yet about version control, I haven't tried. Yeah, the workflow isn't ideal. Sorry.

from wuffs.

mvdan avatar mvdan commented on May 3, 2024

For example, Wuffs-the-language has not needed a string type so far (other than for error messages), or varargs

That's a good point. I'm afraid I don't have a good, specific proposal of what I would add to the language, then. Varargs wouldn't be necessary, but "empty interface" and string types would still be necessary for a println func to be useful.

Is there any way that we could allow printfs in wuffs, as opposed to a print/println? For example, forgetting the syntax for a moment, suppose I could do:

//wuffs:c printf("length = %d", length);

That is, telling the wuffs-c generator to include a line in the C output at this position. Then, if I were generating/testing Go, I'd instead write something like //wuffs:go fmt.Println("length", length).

I realise including this in the language as a formal feature can get ugly; it doesn't need to be guaranteed to work forever, much like Go's print/println. And I also imagine that the include dance with printf in C might get tricky. But it seems to me like a possible way to introduce debug prints without having to worry about Wuff's syntax and language features, nor with modifying generated code by hand.

A different version of this idea is a println; //wuffs:println("length =", length), which would get translated to printf, fmt.Println, or whatever the language equivalent is. Narrower and perhaps simpler to implement reliably, but also not as powerful as "insert any C statement here".

If you're using the wuffs command line tool, such as wuffs test

If only I could without hacks :)

Yeah, the workflow isn't ideal. Sorry.

Oh, that is fine - wuffs-c is not hard to use. I think a "hello world" example using it, complete with how to build a working binary, would be very useful though. It took me a good half hour to figure that out, when the solution wasn't really complex. I just had to dig through the codebase, which is a bit unnecessary. I'll open an issue about it.

from wuffs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.