DulLabs / bhai-lang

A toy programming language written in Typescript
https://bhailang.js.org/
MIT License
3.99k stars 498 forks source link

Adding Function (Funda) for #170 #220

Open thecodacus opened 2 years ago

thecodacus commented 2 years ago

This PR closes issue #154 and Based on #170, this will be the first stage to make it more like a real programming language.

added Functional Programming features,

you can now create funda (functions) to make your code modularized, and not repeat yourself

example

hi bhai
apna funda test(c){
  bol bhai c;
  rakh le bhai "return bhi "+c;
}
bol bhai test("kam kiya bhai");
bye bhai

output

kam kiya bhai
return bhi kam kiya bhai
netlify[bot] commented 2 years ago

Deploy Preview for bhailang-preview ready!

Name Link
Latest commit a2b0d83a4778cf99a4272f41b1f922a58611f871
Latest deploy log https://app.netlify.com/sites/bhailang-preview/deploys/63848e08619000000829e06f
Deploy Preview https://deploy-preview-220--bhailang-preview.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

lgtm-com[bot] commented 2 years ago

This pull request introduces 6 alerts when merging 74b5630d647d2c281d3f49e0f6bc2488857ff033 into fc11311a092c9e62511f1933e25850c0e5a5ddc5 - view on LGTM.com

new alerts:

lgtm-com[bot] commented 2 years ago

This pull request introduces 4 alerts when merging 774d9c13e6cd130011929509445f9c6ef7051f1c into fc11311a092c9e62511f1933e25850c0e5a5ddc5 - view on LGTM.com

new alerts:

lgtm-com[bot] commented 2 years ago

This pull request introduces 3 alerts when merging fc93884ac3262a697a10158d1c80bf4cce5a86ae into fc11311a092c9e62511f1933e25850c0e5a5ddc5 - view on LGTM.com

new alerts:

lgtm-com[bot] commented 2 years ago

This pull request introduces 2 alerts when merging 0ffb32efa626e44dd94b5b7bf7eaa38e334b04b1 into fc11311a092c9e62511f1933e25850c0e5a5ddc5 - view on LGTM.com

new alerts:

ankitchouhan1020 commented 2 years ago

Great work! will check.

ankitchouhan1020 commented 2 years ago
hi bhai

apna funda Counter() { 
  bhai ye hai count = 1;

  apan funda increment() {
    count += 1;
    rakh le bhai count;
  }

  rakh le bhai increment;
}

bhai ye hai tick = Counter();
bol bhai tick();

bye bhai

Does it support closures ? Not working in preview.

thecodacus commented 2 years ago
hi bhai

apna funda Counter() { 
  bhai ye hai count = 1;

  apan funda increment() {
    count += 1;
    rakh le bhai count;
  }

  rakh le bhai increment;
}

bhai ye hai tick = Counter();
bol bhai tick();

bye bhai

Does it support closures ? Not working in preview.

you have a typo "apan" the keyword is "apna" also I just fixed few bugs, it should be working now

image
lgtm-com[bot] commented 2 years ago

This pull request introduces 2 alerts when merging 3336243b2c592dd716952363ab12f5484e57b79a into 0181ca41abb64cff477b3028db13219bf501eaf7 - view on LGTM.com

new alerts:

lgtm-com[bot] commented 2 years ago

This pull request introduces 2 alerts when merging 3dc5b92ef5ac403b4057f4ab0d72b6a637b0d55b into 0181ca41abb64cff477b3028db13219bf501eaf7 - view on LGTM.com

new alerts:

tbhaxor commented 2 years ago

Great work @thecodacus.

I will look into this. I was thinking to have duck typing in the functions. But this will also work

tbhaxor commented 2 years ago

Shouldnt we have it outside hi bhai? Like other languages? Hi bhai is the execution entry point

thecodacus commented 2 years ago

Shouldnt we have it outside hi bhai? Like other languages? Hi bhai is the execution entry point

with the current setup, anything that is outside "hi bhai" is discarded, I am working on "include" features then will try to change this in a new PR

lgtm-com[bot] commented 2 years ago

This pull request introduces 2 alerts when merging 49480494b071b4c5f3b9a0039d262088a955b272 into 0181ca41abb64cff477b3028db13219bf501eaf7 - view on LGTM.com

new alerts:

thecodacus commented 2 years ago

@ankitchouhan1020 if this looks good can we close this PR?

lgtm-com[bot] commented 2 years ago

This pull request introduces 2 alerts when merging f53d781de9276dd8c97c72a5f80aad63722869bf into 0181ca41abb64cff477b3028db13219bf501eaf7 - view on LGTM.com

new alerts:

aniketsingh0104 commented 2 years ago

We'll look into this PR. As its quite large PR we'll take some time. Anyway thanks for working on this.

lgtm-com[bot] commented 2 years ago

This pull request introduces 2 alerts when merging f89fc4f3108a7ef639f379c3eb69ad63006cd5af into a789449c98545de0e23d66968e25ad2eeabd9396 - view on LGTM.com

new alerts:

lgtm-com[bot] commented 2 years ago

This pull request introduces 3 alerts when merging c06b202498ba7af06d2d4dd4e9e232254c1e638f into dd076b3ec71113c29fe63c58128a7ffc7dd7d7c9 - view on LGTM.com

new alerts:

lgtm-com[bot] commented 2 years ago

This pull request introduces 2 alerts when merging bd11d036990c56e3a61a43e6e6f4003f7d641694 into dd076b3ec71113c29fe63c58128a7ffc7dd7d7c9 - view on LGTM.com

new alerts:

lgtm-com[bot] commented 2 years ago

This pull request introduces 2 alerts when merging 3853cf82572a60a46bc5309130a523dd0b1b7544 into dd076b3ec71113c29fe63c58128a7ffc7dd7d7c9 - view on LGTM.com

new alerts:

shankarkrupa commented 2 years ago

@ankitchouhan1020 @aniketsingh0104 or @ristri - could one of you review and approve the PR to be merged with the develop branch? This is such a cool and important feature. Eager to see this spreading against after playing around with this a bit in the netlify preview playground.

aniketsingh0104 commented 2 years ago

To be reviewed this week.

aniketsingh0104 commented 2 years ago

Complete Review would be only possible after the test cases are included.

thecodacus commented 2 years ago

Complete Review would be only possible after the test cases are included.

Thanks for the review till now, I will make the changes and add test cases

lgtm-com[bot] commented 2 years ago

This pull request introduces 2 alerts when merging 567b961b0999fe40a782a979026dbed744f652ed into de68714357e159719b85fae34c0df58d4ba5ce81 - view on LGTM.com

new alerts:

thecodacus commented 2 years ago

Critical: I see test cases are missing from this change specially from Parser. We won't review any PRs which do not contain proper test cases. Please write proper test cases covering positive and negative scenarios for both PARSER and INTERPRETER.

test cases added

thecodacus commented 2 years ago

took me a while to get the time and make the changes :) @aniketsingh0104 please check the changes

lgtm-com[bot] commented 1 year ago

This pull request introduces 2 alerts when merging a2b0d83a4778cf99a4272f41b1f922a58611f871 into de68714357e159719b85fae34c0df58d4ba5ce81 - view on LGTM.com

new alerts:

Heads-up: LGTM.com's PR analysis will be disabled on the 5th of December, and LGTM.com will be shut down ⏻ completely on the 16th of December 2022. Please enable GitHub code scanning, which uses the same CodeQL engine :gear: that powers LGTM.com. For more information, please check out our post on the GitHub blog.

Moulick commented 1 year ago

Can this be merged, looks very useful bhai