Forum > General

Nested procedures

<< < (2/3) > >>

Thaddy:
Yes, that works.

Even C - the most liberal and error prone language - will not evaluate a void function (what we call procedure) as a parameter.
I am not aware of any language that will evaluate a procedure like OP wants.
I came up with about the same as you did:
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$mode objfpc}uses sysutils;Type Seasons=(summer,fall,winter,spring);function str(const value:seasons):string;inline;begin  system.str(value,result);end;var   names:Seasons;   s:string;Begin  For names in seasons Do writeln(str(names) );end. 

Thaddy:
Or as a teaser, works only in trunk:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$mode objfpc}{$if fpc_fullversion < 30301}  {$error this version can not handle this code, needs 3.3.1 or higher}{$ifend}{$modeswitch implicitfunctionspecialization}uses sysutils;Type Seasons=(summer,fall,winter,spring); generic function str<T>(const value:T):string;inline;begin  system.str(Value,result);end;var   names:Seasons;Begin  { implicit specialization }  For names in seasons do writeln(str(names));end. T needs to be ordinal. We can not yet write a restriction like str<T:ordinal> but it is considered to be implemented. Once it is, this code would be very safe.
I show this, because this new feature of implicit specialization is very powerful and I recently started to use it a lot. (but I don't have to write production code anymore.....)

Ten_Mile_Hike:
Thaddy,

Do you remember how in old fashioned Windows Batch language
you could use the "pipe" command "|" to direct the output of one command
into the input of the next command?

============
    ECHO. |TIME
============

I wonder if the Pascal Gods would be angered if I tried to implement this
in Pascal just as an exercise (in frustration). I might try by using pointers
in some naughty way.

egsuh:

Hmmmm.. please try following...

  For names in seasons Do str(names, M1.Lines[M1.Lines.Add('')]);

BildatBoffin:

--- Quote from: Ten_Mile_Hike on June 13, 2024, 10:59:40 pm ---I wonder if the Pascal Gods would be angered if I tried to implement this
in Pascal just as an exercise (in frustration). I might try by using pointers
in some naughty way.

--- End quote ---

Some languages call that https://en.wikipedia.org/wiki/Uniform_Function_Call_Syntax. The FPC equivalent for now is to define type helpers.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version