{"id":8615,"date":"2022-05-30T15:47:26","date_gmt":"2022-05-30T13:47:26","guid":{"rendered":"https:\/\/monodes.com\/predaelli\/?p=8615"},"modified":"2022-05-30T15:47:28","modified_gmt":"2022-05-30T13:47:28","slug":"let-the-compiler-dispose-of-an-expanded-value","status":"publish","type":"post","link":"https:\/\/monodes.com\/predaelli\/2022\/05\/30\/let-the-compiler-dispose-of-an-expanded-value\/","title":{"rendered":"Let the compiler dispose of an expanded value"},"content":{"rendered":"\n<p class=\"has-black-color has-luminous-vivid-amber-background-color has-text-color has-background has-normal-font-size\" style=\"font-style:normal;font-weight:900\">Note: I wrote this notes on august 2021, but I shall publish them now in the state thay are otherwise I will lose memory of their existence yet another time&#8230;<\/p>\n\n\n\n<p>Lately I discovered that Liberty Eiffel needs expanded classes to be DISPOSABLE to get rid of a garbage collector like Rust does.<\/p>\n\n\n\n<p>So I was quite disappointed to discover that currently a simple source like<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\" data-line=\"\">class DISPEXPEX -- disposable expanded example\ncreate {ANY} make\nfeature {ANY}\n   make\n      local a: DISPEXP\n      do \n         print(a.out)\n      end\nend   \n\nexpanded class DISPEXP -- Disposable and expanded\ninsert DISPOSABLE\nfeature {ANY}\n      name: STRING\n      value: INTEGER\nfeature {} \n      dispose \n         do \n               print(&quot;disposing DISPEXP&quot;)\n            end\n         \nend\n<\/code><\/pre>\n\n\n\n<p>does not even compile. It seems that DISPEXP must redefine out to let people actually use it. But changing DISPESP to <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\" data-line=\"\">expanded class DISPEXP\n   -- Disposable and expanded\ninsert DISPOSABLE\n   redefine out end\nfeature {ANY}\n      name: STRING\n      value: INTEGER\n      out: STRING\n   do\n      if name\/=Void then\n         Result := &quot;DISPEXP&quot;+name+&quot; &quot;+value.out\n      else\n         Result := &quot;nameless DISPEXP&quot;\n      end\nend\nfeature {} \n      dispose \n         do \n               print(&quot;disposing DISPEXP&quot;)\n            end\n         \nend<\/code><\/pre>\n\n\n\n<p>doesn&#8217;t work as the compiler says that <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">****** Error: Invalid usage of feature `to_pointer' of class ANY. (The target which is of type DISPEXP cannot be converted to a memory address.)\n\nThe source lines relevant to this message are the following:\n\nLine 421 column 4 in ANY (\/home\/paolo\/src\/liberty-eiffel\/src\/lib\/kernel\/any.e):\n   to_pointer: POINTER\n   ^                  \nLine 8 column 16 in DISPEXPEX (\/home\/paolo\/tmp\/dispexpex.e):\n         print(a.to_pointer.out)<\/pre>\n\n\n\n<p>Most programmers would have already rejected Eiffel by now. First of all why &#8211; for Heaven sake &#8211; doesn&#8217;t to_pointer have a require not is_expanded? <\/p>\n\n\n\n<p>The answer is simple: ANY does not have an is_expanded or a is_reference feature. At first I was going to write it as <\/p>\n\n\n\n<p>is_expanded: BOOLEAN do Result := <\/p>\n\n\n\n<p>instead it seems that introspection &#8211; i.e the usage of internals which require explicit support from the compiler &#8211; is not required as it can be implemented as <\/p>\n\n\n\n<p>is_expanded: BOOLEAN local like_current: like Current do Result := like_current \/= Void end<\/p>\n\n\n\n<p>but it cannot work. In fact the compiler (correctly) argues that<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">****** Error: Such a weird comparison with Void is not allowed because it would be always True. (See explaination below.)\n\nLine 21 column 27 in DISPEXP (\/home\/paolo\/tmp\/dispexp.e):\n   Result := like_current \/= Void\n                          ^      \n------\n****** Fatal Error: The declaration type of `like_current' is obviously expanded (i.e. the written type mark is \"DISPEXP\"). You can use the Void comparison only when other type mark is a reference type or, if it is an expanded type, it must be an anchor or some formal generic argument. Fix this error first.<\/pre>\n\n\n\n<p>So in the end one could write ANY&#8217;s is_expanded as<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\" data-line=\"\">is_expanded: BOOLEAN do Result := to_interals.type_is_expanded end<\/code><\/pre>\n\n\n\n<p>that implies that a simple class such as DISPEXP must insert INTERNALS_HANDLER. <\/p>\n\n\n\n<p>So now we understand why <strong>to_pointer<\/strong> is built not to even compile when used on expanded values. It is a simplification that made life quite simpler to implementors.<\/p>\n\n\n\n<p>There&#8217;s a issue. Why did they add &#8220;<strong>to_pointer<\/strong>&#8221; at all? You may promptly answer: because you need it to interact with low-level code. But we do have the <strong>$<\/strong> operator for this. And wonder of wonders, it works smoothly on expanded objects.  But it is meant to be used on the final name of a feature which is not a constant attribute or by the name of some local variable. Not even <strong>Current<\/strong>. If it wasn&#8217;t for the latter limitation one could write <strong>to_pointer: POINTER do Result := $Current end<\/strong>  <\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>&#8230; more on this later<\/p>\n","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\">Note: I wrote this notes on august 2021, but I shall publish them now in the state thay are otherwise I will lose memory of their existence yet another time&#8230; Lately I discovered that Liberty Eiffel needs expanded classes to be DISPOSABLE to get rid of a garbage collector like Rust does. So I was&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"https:\/\/monodes.com\/predaelli\/2022\/05\/30\/let-the-compiler-dispose-of-an-expanded-value\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":4,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-8615","post","type-post","status-publish","format-standard","hentry","category-senza-categoria"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p6daft-2eX","jetpack-related-posts":[{"id":6836,"url":"https:\/\/monodes.com\/predaelli\/2020\/03\/06\/what-is-faster-in-c-a-struct-or-a-class-c-architects-medium\/","url_meta":{"origin":8615,"position":0},"title":"What Is Faster In C#: A Struct Or A Class? &#8211; C# Architects &#8211; Medium","author":"Paolo Redaelli","date":"2020-03-06","format":false,"excerpt":"What do you think is faster: filling an array with one million structs, or filling an array with one million classes? Mark Farragher ask himself What Is Faster In C#: A Struct Or A Class? - C# Architects - on Medium. But of course the third version is faster because\u2026","rel":"","context":"In &quot;Documentations&quot;","block_context":{"text":"Documentations","link":"https:\/\/monodes.com\/predaelli\/category\/documentations\/"},"img":{"alt_text":"Mark Farragher","src":"https:\/\/i0.wp.com\/monodes.com\/predaelli\/wp-content\/uploads\/sites\/4\/2020\/03\/1IyCy3Cj8Kuv759UIaFq3aw.jpeg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":8612,"url":"https:\/\/monodes.com\/predaelli\/2022\/05\/30\/eiffel-rust-and-memory-management\/","url_meta":{"origin":8615,"position":1},"title":"Eiffel, Rust and memory management","author":"Paolo Redaelli","date":"2022-05-30","format":false,"excerpt":"It already passed one year almost two years since in \"Oh my lazyness!\" when I wrote I shall restart my efforts on Liberty EIffel and Monodes\u2026 \ud83d\ude41 I hope to integrate them in my current effort. While I haven't been able to integrate Eiffel in the endeavour that is keeping\u2026","rel":"","context":"In &quot;Eiffel&quot;","block_context":{"text":"Eiffel","link":"https:\/\/monodes.com\/predaelli\/category\/eiffel\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":7206,"url":"https:\/\/monodes.com\/predaelli\/2020\/05\/12\/how-to-increase-the-size-of-a-linux-lvm-by-expanding-the-virtual-machine-disk\/","url_meta":{"origin":8615,"position":2},"title":"How to Increase the size of a Linux LVM by expanding the virtual machine disk","author":"Paolo Redaelli","date":"2020-05-12","format":false,"excerpt":"How to Increase the size of a Linux LVM by expanding the virtual machine disk How to Increase the size of a Linux LVM by expanding the virtual machine disk Posted by Jarrod on December 12, 2012 Leave a comment (284) Go to comments This post will cover how to\u2026","rel":"","context":"In &quot;Documentations&quot;","block_context":{"text":"Documentations","link":"https:\/\/monodes.com\/predaelli\/category\/documentations\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":9850,"url":"https:\/\/monodes.com\/predaelli\/2022\/11\/15\/tollerante-nella-pratica\/","url_meta":{"origin":8615,"position":3},"title":"Tollerante nella pratica","author":"Paolo Redaelli","date":"2022-11-15","format":false,"excerpt":"La Chiesa \u00e8 intransigente sui principi, perch\u00e9 crede, \u00e8 tollerante nella pratica, perch\u00e9 ama. I nemici della Chiesa sono invece tolleranti sui principi, perch\u00e9 non credono, ma intransigenti nella pratica, perch\u00e9 non amano. La Chiesa assolve i peccatori, i nemici della Chiesa assolvono i peccati.da p. Reginald Garrigou-Lagrange, Dieu, son\u2026","rel":"","context":"In &quot;Senza categoria&quot;","block_context":{"text":"Senza categoria","link":"https:\/\/monodes.com\/predaelli\/category\/senza-categoria\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":15164,"url":"https:\/\/monodes.com\/predaelli\/2026\/02\/25\/memory-constraints\/","url_meta":{"origin":8615,"position":4},"title":"Memory constraints","author":"Paolo Redaelli","date":"2026-02-25","format":false,"excerpt":"The RAM shortage might be the best thing to happen in software development in years For years, the answer was simple: throw more RAM at it. Software happily expanded to fill whatever space it was given.Now memory limits are tightening again and that\u2019s forcing a long-overdue rethink. Developers once built\u2026","rel":"","context":"In &quot;Senza categoria&quot;","block_context":{"text":"Senza categoria","link":"https:\/\/monodes.com\/predaelli\/category\/senza-categoria\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/monodes.com\/predaelli\/wp-content\/uploads\/sites\/4\/2026\/02\/641625752_943623337992567_3648687791429867492_n.webp?fit=512%2C640&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":1229,"url":"https:\/\/monodes.com\/predaelli\/2016\/04\/01\/minimal-programming\/","url_meta":{"origin":8615,"position":5},"title":"Minimal Programming","author":"Paolo Redaelli","date":"2016-04-01","format":false,"excerpt":"Such an interesting site this Minimal Programming. Feels old school, written by proficient people! Therefore, minimal programming means minimal code: no code duplication maximal expressiveness: readable code that directly reflects the underlying task minimal overlap: every piece of information can be found in exactly one place maximal orthogonality: clear separation\u2026","rel":"","context":"In &quot;Documentations&quot;","block_context":{"text":"Documentations","link":"https:\/\/monodes.com\/predaelli\/category\/documentations\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/posts\/8615","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/comments?post=8615"}],"version-history":[{"count":0,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/posts\/8615\/revisions"}],"wp:attachment":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/media?parent=8615"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/categories?post=8615"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/tags?post=8615"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}