DEV Community

Discussion on: Getting started with MojiScript: FizzBuzz (part 1)

Collapse
 
jochemstoel profile image
Jochem Stoel • Edited

Where/how exactly do you let sleep not require an async/await function? Your sleep is identical to mine but mine requires you to await it, never found a way around that. Neither mojiscript/threading/sleep or mojiscript/core/pipe exports anything async.

const sleep = require('mojiscript/threading/sleep')
const pipe = require('mojiscript/core/pipe')
const log = console.log
const range = require('mojiscript/list/range')
const map = require('mojiscript/list/map')

const sleepAndLog = pipe([
    sleep(1000), // why this be work??
    log
])
pipe([
    ({ start, end }) => range(start)(end),
    map(sleepAndLog)
])({start: 0, end: 10})

Secondly, do you deliberately not comment your exports or is it lazyness? I can help you with that. Most looks pretty straightforward.

And last, maybe you should define a main property in your package.json so that mojiscript can be required the conventional way.

I also want to suggest you stop calling this a language but that is just my opinion and really up to you.

Collapse
 
joelnet profile image
JavaScript Joel

Where/how exactly do you let sleep not require an async/await function?

MojiScript's pipe, map, filter, and reduce work with both async and sync code. They do not need to await anything.

You could look at call, which will execute with a function after testing if the value is or is not a Promise. github.com/joelnet/MojiScript/blob...

Your sleep is identical to mine but mine requires you to await it, never found a way around that.

Post your code, I'll figure out the difference.

Secondly, do you deliberately not comment your exports or is it lazyness?

I'm still looking for a solution for auto-generated documentation. So I am holding off on putting docs directly into the code because the format may differ based on the tool I select. I have posted about the problems I am having here: Let's talk about the state of auto-generated documentation tools for JavaScript

There are full docs for MojiScript here: github.com/joelnet/MojiScript/blob...

And last, maybe you should define a main property in your package.json so that mojiscript can be required the conventional way.

I thought about this, but decided not to. I don't want the entire library being imported into your project. Only the functions you need will be imported to keep the size down.

I also want to suggest you stop calling this a language but that is just my opinion and really up to you.

This has been discussed in the Discord chat. More on the reasons why will be written shortly.

Collapse
 
jochemstoel profile image
Jochem Stoel

Joel, I would like to point out that a main.js does not prevent you from importing only the functions you need. It doesn't matter.

First of all, import statements will still work.

// this does not care about main.js in package.json
import pipe from 'mojiscript/core/pipe'

Secondly you can also require selectively only the stuff you need, exactly like import.

const { readFileSync, mkdir } = require('fs')
// or in your case
const { pipe, sleep, log } = require('mojiscript')
Thread Thread
 
joelnet profile image
JavaScript Joel

The design decision to create every function as it's own import was made to remove a footgun.

The footgun removed is the ability to import the entire library when you only need a few functions.

This way, the output bundle sir is only as big as the functions you import.

So MojiScript will have a microscopic footprint in your final output bundle because it is no longer possible to import the entire bundle.

Thread Thread
 
jochemstoel profile image
Jochem Stoel

I made a script called mojifier that converts your module into a single object with everything included / proper namespaces by iterating the directories/files.