← 输入框|github.com|刷新
Skip to content

Default arguments not working ? #2109

Closed

Description

@rebcabin

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')

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions