Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Gabe Johnson
    @gabejohnson
    *post
    syntax and operator are built into the compiler
    David Schalk
    @dschalk

    I pasted this:

    function Monad(z = 'default', ID = 'tempMonad') {
    this.x = z;
    this.id = ID;
    };

    Monad.prototype.bnd = function (func, ...args) {
    var _this = this;
    if (func instanceof Promise) {
    _this.getVal(func,this.x,args);
    }
    var m = func(this.x, ...args)
    var ID;
    if (m instanceof Monad) {
    ID = testPrefix(args, this.id);
    _this[ID] = new Monad(m.x, ID);
    return _this[ID];
    }
    else return m;
    };

    Monad.prototype.ret = function (a) {
    return window[this.id] = new Monad(a, this.id);
    };

    var mM1 = new Monad (1, 'mM1');
    var mM2 = new Monad (2, 'mM2');
    var mM3 = new Monad (3, 'mM3');
    var cube = x => xxx;
    var square = x => x*x;
    var add = a => b => a+b;

    console.log(mM1.bnd(mM2.ret))

    operator >>= left 1 = (left, right) => {
    return #${left}.bnd(${right});
    };

    mM3 >>= cube >>= add(3) >>= square

    And I got what I wanted:
    function Monad(z_384 = "default", ID_385 = "tempMonad") {
    this.x = z_384;
    this.id = ID_385;
    }
    Monad.prototype.bnd = function (func_386, ...args_387) {
    var _this_388 = this;
    if (func_386 instanceof Promise) {
    _this_388.getVal(func_386, this.x, args_387);
    }
    var m_389 = func_386(this.x, ...args_387);
    var ID_390;
    if (m_389 instanceof Monad) {
    ID_390 = testPrefix(args_387, this.id);
    _this_388[ID_390] = new Monad(m_389.x, ID_390);
    return _this_388[ID_390];
    } else return m_389;
    };
    Monad.prototype.ret = function (a_391) {
    return window[this.id] = new Monad(a_391, this.id);
    };
    var mM1_374 = new Monad(1, "mM1");
    var mM2_375 = new Monad(2, "mM2");
    var mM3_376 = new Monad(3, "mM3");
    var cube_377 = (x_392) => x_392 x_392 x_392;
    var square_378 = (x_393) => x_393 * x_393;
    var add_379 = (a_394) => (b_395) => a_394 + b_395;
    console.log(mM1_374.bnd(mM2_375.ret));
    mM3_376.bnd(cube_377).bnd(add_379(3)).bnd(square_378);
    David Schalk
    @dschalk
    This is encouraging, but I still don't know how to import "operator" into http://schalk.net:3055 or anywhere else. How do you access "macro" and "operator". For whatever it might be worth: I am working in Ubuntu 17.04 in a Cycle.js application using webpack.
    David Schalk
    @dschalk
    Ooops. cube, square, and add are supposed to map values to values wrapped in instances of Monad. I'm trying to fix that now.
    David Schalk
    @dschalk

    I pasted this:

    function Monad(z) {
    this.x = z;
    this.bnd = function (func, ...args) {
    return func(this.x, ...args)
    }
    this.ret = function (val = 0) {
    return new Monad(val);
    }
    };

    function ret (v) {
    return new Monad(v);
    }

    var cube = x => ret(xxx);
    var square = x => ret(x*x);
    var add = a => b => ret(a+b);

    operator >>= left 1 = (left, right) => {
    return #${left}.bnd(${right});
    };
    ret(3) >>= cube >>= add(3) >>= square
    and I got this:
    function Monad(z_62) {
    this.x = z_62;
    this.bnd = function (func_63, ...args_64) {
    return func_63(this.x, ...args_64);
    };
    this.ret = function (val_65 = 0) {
    return new Monad(val_65);
    };
    }
    function ret(v_66) {
    return new Monad(v_66);
    }
    var cube_55 = (x_67) => ret(x_67 x_67 x_67);
    var square_56 = (x_68) => ret(x_68 * x_68);
    var add_57 = (a_69) => (b_70) => ret(a_69 + b_70);
    ret(3).bnd(cube_55).bnd(add_57(3)).bnd(square_56);

    This is exactly what I wanted. ret(3) >>= cube >>= add(3) >>= square
    compiled to ret(3).bnd(cube_55).bnd(add_57(3)).bnd(square_56). This should
    evaluate to an instance of Monad with value 900.

    David Schalk
    @dschalk
    I still don't know how to get "operator" or "macro" into my application. By the way, I ran the result in the Chrome console and got what I expected: "Monad {x: 900, bnd: ƒ, ret: ƒ}"
    David Schalk
    @dschalk
    PROBLEM SOLVED I ran sjs on the operator code (above) and got the expected result. I have been updating my package.json file and inadvertently solved my problem. Thank you Gabe @gabejohnson for showing me where to play around with sweet-js. The Haskell bind operator ">>=" is now in my javascript project doing pretty much the same thing it does in the Haskell programming language. I'll see what practical use it might have at http://schalk.net:3055, a work in progress going through some major upheavals.
    Gabe Johnson
    @gabejohnson
    :thumbsup:
    David Schalk
    @dschalk
    Does anyone have an opinion regarding presets, plugins, or loaders to facilitate compiling sweet code with webpack?
    Dan
    @danneu
    isn't sjs script.js supposed to read .babelrc? it doesn't do any of my transformations. meanwhile babel script.js will indeed transform my code according to my .babelrc
    unsure of how to debug or see if i'm misunderstanding the usage
    Gabe Johnson
    @gabejohnson
    @danneu I don't recall how the pipeline w/ babel is working, but you should be able to pass --no-babel and then pipe the output from sjs through babel
    Gabe Johnson
    @gabejohnson
    @danielo515 you can ask questions about sweet here
    Daniel Rodríguez Rivero
    @danielo515
    Thanks @gabejohnson
    Daniel Rodríguez Rivero
    @danielo515
    Does anyone know how to build a macro like this?
    
    
    
    
    This phone keyboard.....
    ```concat $ 1 2 3
    // Which will compile to
    concat (1) (2) (3)
    The $ is the actual macro
    Gabe Johnson
    @gabejohnson
    @danielo515 I added an answer in #750
    Daniel Rodríguez Rivero
    @danielo515
    Have you checked my latest answer?
    Badicla
    Basically what I said is that changing a pair of parents by a single dollar sign is not good enough
    Gabe Johnson
    @gabejohnson
    I understand your frustration @danielo515 but that issue isn't really the forum for discussing the implementation of a particular operator
    The main reason you're having trouble is because you are trying to emulate syntax from a language in which whitespace is significant. That's going to be very difficult to do in JS
    Gabe Johnson
    @gabejohnson
    One option would be to write a macro which prefixed your entire source file and then walk the token tree looking for $. That way you'd have a handle on the previous expression as well as the rest of the token tree.
    You could use it as so:
    enable // this is the macro
    
      // your macro finds an expression (log) and looks for $
      // the you can transform the following tokens (1 and 2)
      log $ 1 2 
    
    // a guard identifier used to end consumption of the token tree
    // or you could let the macro work to the end of the enclosing block
    // if not at the top level
    disable
    Gabe Johnson
    @gabejohnson
    But you're essentially writing a compiler at that point (probably delegating most of the work to expand)
    Another syntactic option
    enable {
      // only handle the code between the delimiters
    }
    or
    {
      enable
      // ...
    }
    Daniel Rodríguez Rivero
    @danielo515
    @gabejohnson you are absolutely right, on everything. I'll leave that issue for tracking the bug. About themacro,do you think that adding commas between the arguments could help?
    jtenner
    @jtenner
    Hey guys. Just getting started with sweet.js, and I find the docs really confusing.
    jtenner
    @jtenner
    I look at it, and my brain melts
    any help? It might involve walking me through some steps and figuring things out first.
    mtom55
    @mtom55

    Hi all...

    I was trying to get the following syntax to work:

    function hello(a:integer:>10, b:string:not-empty) {
        const myString = a + B
        return:string:not-empty myString
    }

    to convert to

    function hello(a, b) {
        if (!Number.isInteger(a))   throw new Error('a must be an integer')
        if (!(a > 10))              throw new Error('a must be > 10')
        if (typeof b !== 'string')  throw new Error('b must be a string')
        const myString = a + b
    
        const __returnValue = myString
        if (typeof __returnValue !== 'string') throw new Error('return value must be a string')
        if (__returnValue === '')              throw new Error('return value can not be an empty string')
    
    
        return:string:not-empty myString
    }

    I've tried for days I just can't get it to work

    Matías Fidemraizer
    @mfidemraizer
    @mtom55 design by contract ;P
    Pablo
    @Nullpo
    Hi! Sorry for this question, but this project is deprecated? I'm interested to work whit sweet.js, but the last commits are a year ago :(
    Andrew Miller
    @andrewmiller1
    @wdanilo It's not unmaintained. It's just that the maintainer is busy.
    Levi Roberts
    @bugs181

    Very noobie to SweetJS and having issues with doing something that I think should be fairly simple. Tutorial is not being very helpful because I'm getting odd errors about things not being defined.

    Here's what I'm trying to do:

    syntax req = function(ctx) {
      const moduleName = ctx.next().value
      return #`const ${moduleName} = require('${moduleName}')`
    }
    
    req someModule
    // output:
    const someModule_4 = require("${moduleName}");
    I had assumed everything inside the template literal would use the variables from the syntax function.
    When I try to change this to something like:
    return #`const ${moduleName} = require(${fromStringLiteral(moduleName)})`
    
    Output:
    evalmachine.<anonymous>:6
        return syntaxTemplate(1, moduleName_2, fromStringLiteral(moduleName_2));
                                 ^
    
    ReferenceError: fromStringLiteral is not defined
        at evalmachine.<anonymous>:6:30
    I have this in my file also:
    import { fromStringLiteral } from '@sweet-js/helpers' for syntax
    Hossein Alipour
    @HosseinAlipour
    I just saw Sweet.js and wonder is it compatible with debuging?
    Victor Buzzegoli
    @vbuzzegoli
    Hey everyone, is there any way to have the syntaxes abstracted away from the files to be transpiled? In a dedicated file for example?
    Brian Beale
    @brianbeale
    I like this library, but I'm wondering if it's still actively maintained or there is a more active alternative
    XingZiLong
    @SketchySketch
    I wonder if it is contained by JS standard library.
    Ian Rumac
    @ianrumac
    Hi folks, just wondering, is there anything going on with support for macros in regards to higlighting VSCode/Webstorm or similar?
    I'm thinking of migrating my kotlin DSL to JS and just looking at options, sweet seems dope as hell, but the lack of higlighting is gonna kill me probs :joy: