简体   繁体   中英

Stack overflow with recursive function

I'm trying to make a recursive function where i pass in a integer and a list. I want to append a certain number of "-" (dashes) to the list if the length of the list is less than the integer as follows:

let rec dashes (longest, l1) =  
    if length l1 = longest then l1 
    else ["-"]@l1@dashes(longest,l1);;

However I get a stack overflow and I'm not sure why.

您对dashes递归调用将通过原始的l1参数传递,因此列表长度永远不会增加,并且终止条件仍为false。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM