Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default arguments not working ? #2109

Closed
rebcabin opened this issue Jul 5, 2023 · 0 comments · Fixed by #2618
Closed

Default arguments not working ? #2109

rebcabin opened this issue Jul 5, 2023 · 0 comments · Fixed by #2618

Comments

@rebcabin
Copy link
Contributor

rebcabin commented Jul 5, 2023

The following works in CP, but not LP.

from random import random

from lpython import (i8, i32, i64, f32, f64,
                     u8, u32,
                     TypeVar, Const,
                     dataclass,
                     # random
                     )
from numpy import (empty, sqrt, float32, float64,
                   int8, int32, array, # ndarray
                   )


def coin_flip(probability : f64=f64(0.5)) -> i8:
    """roll 1 bit"""
    result : i8 = i8(0)
    r : f64 = random()
    if r < probability:
        result = i8(1)
    return result


def h() -> None:
    i : i32
    for i in range(10):
        coin : i8 = coin_flip()
        print(coin, end='')
    print('')


if __name__ == "__main__":
    h()
(lp) ┌─(~/CLionProjects/lpython/lasr/LP-pycharm)─────────────────────────────────────────────────────────────────────────────────────────────────────────(brian@Golf37:s000)─┐
└─(11:36:44 on brian-lasr ✹ ✭)──> PYTHONPATH='../../src/runtime/lpython' python issue2107.py                                                          1 ↵ ──(Wed,Jul05)─┘
1
1
1
1
1
0
1
1
0
0
(lp) ┌─(~/CLionProjects/lpython/lasr/LP-pycharm)─────────────────────────────────────────────────────────────────────────────────────────────────────────(brian@Golf37:s000)─┐
└─(11:36:49 on brian-lasr ✹ ✭)──> ~/CLionProjects/lpython/src/bin/lpython -I. issue2107.py                                                                ──(Wed,Jul05)─┘
semantic error: Number of arguments does not match in the function call
  --> issue2107.py:26:21
   |
26 |         coin : i8 = coin_flip()
   |                     ^^^^^^^^^^^ (found: '0', expected: '1')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant