Skip to content

Commit 55dd43c

Browse files
authoredFeb 28, 2025
Merge pull request #1877 from RickBarretto/deprecate-stack-discard-issue-1870
[Core\unstack] Deprecate `unstack.discard`
2 parents a81d143 + 53ec5c5 commit 55dd43c

File tree

2 files changed

+13
-22
lines changed

2 files changed

+13
-22
lines changed
 

‎src/library/Core.nim

+12-21
Original file line numberDiff line numberDiff line change
@@ -1437,9 +1437,7 @@ proc defineModule*(moduleName: string) =
14371437
args = {
14381438
"number" : {Integer}
14391439
},
1440-
attrs = {
1441-
"discard" : ({Logical},"do not return anything")
1442-
},
1440+
attrs = NoAttrs,
14431441
returns = {Any},
14441442
example = """
14451443
1 2 3
@@ -1448,30 +1446,23 @@ proc defineModule*(moduleName: string) =
14481446
1 2 3
14491447
b: unstack 2 ; b: [3 2]
14501448
..........
1449+
; You can also discard the values using `discard`
14511450
1 2 3
1452-
unstack.discard 1 ; popped 3 from the stack
1451+
discard unstack 1 ; popped 3 from the stack
14531452
""":
14541453
#=======================================================
1455-
if Stack[0..SP-1].len < x.i: Error_StackUnderflow()
1456-
1457-
let doDiscard = (hadAttr("discard"))
1454+
if Stack[0..SP-1].len < x.i:
1455+
Error_StackUnderflow()
14581456

14591457
if x.i==1:
1460-
if doDiscard: discard stack.pop()
1461-
else: discard
1458+
discard
14621459
else:
1463-
if doDiscard:
1464-
var i = 0
1465-
while i<x.i:
1466-
discard stack.pop()
1467-
i+=1
1468-
else:
1469-
var res: ValueArray
1470-
var i = 0
1471-
while i<x.i:
1472-
res.add stack.pop()
1473-
i+=1
1474-
push(newBlock(res))
1460+
var res: ValueArray
1461+
var i = 0
1462+
while i<x.i:
1463+
res.add stack.pop()
1464+
i+=1
1465+
push(newBlock(res))
14751466

14761467
builtin "until",
14771468
alias = unaliased,

‎src/scripts/console.art

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ lookup: function [what :string :literal :regex :type][
176176
]
177177

178178
PrintFList results "found"
179-
unstack.discard size stack
179+
discard unstack size stack
180180
]
181181

182182
Repl: #[autocomplete?: true, hints?: true, verbose?: true]

0 commit comments

Comments
 (0)