Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) by mail-b.sr.ht (Postfix) with ESMTPS id 6D4C8FF115 for <~duangle/scopes@lists.sr.ht>; Sat, 4 Jul 2020 17:31:05 +0000 (UTC) Authentication-Results: mail-b.sr.ht; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Od9g8vAf Received: by mail-qk1-f180.google.com with SMTP id 145so28961125qke.9 for <~duangle/scopes@lists.sr.ht>; Sat, 04 Jul 2020 10:31:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:subject:to:cc:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XW2hjuXBw6eeOl/0BSd0cKLb58BearaCOyv3j2IrPXk=; b=Od9g8vAfAWDiFBvhZiQ01340/suEYkeuwFzav+liA6kNm0mvHG/6u3zFXj02fN84id OvxvsDU3KLt3jtXhWCvvjFTGgMkEVTk2DC0XNZH+zEv7RFgSKrvzN0HCm7bvInpY2pQX LJFZt/EaouOPMYC1bMtd9Hmr30/Q5851gMKctKLqS5uyMSGsy4CxOF5wWZ9cnSWkmBu5 mlPZ0ptOIA8VLen2REozq1JgT1I7415Sy67mMS7NGWk9xkskGXe55tKz9IwRD/wjMRG3 TyIqdRHu1aEd7P/TtsCA5aaNUdP4PwihRivGTa4UQf7Oga+woAIGWjVT6hnPFd//9cZS j7Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:subject:to:cc:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XW2hjuXBw6eeOl/0BSd0cKLb58BearaCOyv3j2IrPXk=; b=UyswxBRjlhO7fNUyZ6sgZxb1bPAGwdHQlGPsshnMGx6rvGmTR+sRg1pIS0KwQy4Tri 9JLN+XiVvi9wv8ppSp4OrnaVpkrNX3EuN/K4QxZXImF1/Y41xUA1Rz0EqkSAYCDA5tca Qeqgh7lXAEWYffNz64XgYUNI4sHuhQ9U7QEvuTB/AE3k3hE5YGGdomLhtLTpCWKaMB9N HA/p00iYBNMyrUGAJh04UdoXqdMiTcAWhOZvD/dIjN2OszDBHE0t2AI+KxSrusMEPhs1 xvjha3DLGuCee7ew1mstpfKFKMSHAXJNU7tQsz+uLQ3ChS1qe71nNqYSRky1wgVquCtg sOBA== X-Gm-Message-State: AOAM5324xHlVFCkeLnTW1NIoQF9GHKOIZh8fwut23JOCVXziMwA27ayu k9al0tGMAxQ4RVRmAW0+zsRZCDz2tzz/sw== X-Google-Smtp-Source: ABdhPJyJ3og7bE+MkEqJD0atI0NMnATfZHrYp00gqLTf3uPN5d0pg3UNR9QxjL3RlIyUJTTU2yHc+A== X-Received: by 2002:a05:620a:1301:: with SMTP id o1mr41689427qkj.223.1593883864986; Sat, 04 Jul 2020 10:31:04 -0700 (PDT) Received: from pop-os ([2804:d59:26a4:c100:d8ad:591f:cc03:16f]) by smtp.gmail.com with ESMTPSA id b7sm12335053qkl.18.2020.07.04.10.31.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Jul 2020 10:31:04 -0700 (PDT) Date: Sat, 04 Jul 2020 12:30:54 -0500 From: Westerbly Snaydley Subject: Re: unexpected behavior with arrays? To: Shawn Walker Cc: ~duangle/scopes@lists.sr.ht Message-Id: In-Reply-To: References: X-Mailer: geary/3.36.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable On Fri, Jul 3, 2020 at 22:45, Shawn Walker =20 wrote: > $0 =E2=96=BA x @ 0 > $0 =3D 0 TL;DR: you have a stale stack pointer. As you probably know, `alloca`'d pointers are not meant to survive=20 beyond the function frame, and the way the REPL works is that it wraps=20 every evaluated expression in a function; the result of this is that=20 it's impossible to keep function-local pointers valid between=20 evaluations. What you may do is use a global array instead, or even one=20 using the `local` keyword since that was improved recently to work=20 better in this situation. Your code will work like this: ``` $0 =E2=96=BA local x : (array i32 5) (arrayof i32 0 0 0 0 0) $0 =E2=96=BA x @ 0 =3D 1 $0 =E2=96=BA x @ 1 =3D x @ 0 + 1 $0 =E2=96=BA x @ 0 $0 =3D 1 $1 =E2=96=BA x @ 1 $1 =3D 2 ``` Westerbly (radgeRayden) Snaydley.