Constant request: #LOREM$
Re: Constant request: #LOREM$
Why not create #LOREM$ in a resident. Isn't this the kind of thing they are there for?
I have a bunch of macros and "stuff" that I want (need?) in residents. Always available - works well.
I have a bunch of macros and "stuff" that I want (need?) in residents. Always available - works well.
Re: Constant request: #LOREM$
That just adds frustration in these situations:bosker wrote:Why not create #LOREM$ in a resident. Isn't this the kind of thing they are there for?
I have a bunch of macros and "stuff" that I want (need?) in residents. Always available - works well.
PB Fanatic wrote:...I'm talking about when sharing code in these forums, too...
Re: Constant request: #LOREM$
+1..... How about a single .pbi include file, posted as a sticky on the forum? Everybody could update that post so that we have a comprehensive file to support a range of code snippets......
Re: Constant request: #LOREM$
Imbedding test data into the compiler is IMO bloat.
An optional include file makes much more sense, as does bosker's suggestion.
I even like my suggestion to include a garbage generator better than including a #LOREM constant.
Enough typed.
An optional include file makes much more sense, as does bosker's suggestion.
I even like my suggestion to include a garbage generator better than including a #LOREM constant.
Enough typed.
Keep it BASIC.
Re: Constant request: #LOREM$
Well there are texts one could use, but you immediately have to regard the different OSs, unless your code isn't already determined.skywalk wrote:The same goes for simple images which can be found in the install folder, like #PB_Compiler_Home+"Examples\Sources\Data\CdPlayer.ico".
Code: Select all
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
file$ = "readme.txt"
CompilerElse
file$ = "README"
CompilerEndIf
ReadFile(1, #PB_Compiler_Home + file$)
While Eof(1) = 0
astring$ = ReadString(1)
If l > 10 And l < 19
string$ = string$ +Chr(32)+ astring$
EndIf
l+1
Wend
CloseFile(1)
Debug string$
End
Code: Select all
Debug RemoveString(GetClipboardText(), Chr(10))
... you can try my "#LOREM$ your own"
Code: Select all
Procedure.s Lorem(length.i)
For i = 1 To length
If an = 0 ; grant capital letter at startup & new sentence
x = Random(25) + 65 : an = 1
Else
x = Random(24) + 97
EndIf
If ch <> 0 ; prevent startup/sentence with space (resp. dot)
a = Random(4)
b = Random(3)
If a = b Or ch > 9 ; create words by chance or if getting too long
x = 32 : ch = 0
EndIf
EndIf
If z = x :x + 1 ; prevent double-letters by moving x by one position
ElseIf z = 33 : x = 46 ; create sentence if space (32+1) occured twice in a row
lorem$ = lorem$ + Chr(x) + Chr(32) : ch = -1 : an = 0
lorem$ = ReplaceString(lorem$, " .", ".") ; remove prior space & possible double-dots
lorem$ = ReplaceString(lorem$, "..", ".")
Else
lorem$ = lorem$ + Chr(x)
EndIf
ch + 1 ; count 'word-letters'
z = x ; set z to prevent double-letters
Next
lorem$ = RTrim(lorem$, " ") ; clean up possible text-ending and apply s.th. defined
lorem$ = RTrim(lorem$, ".")
lorem$ = lorem$ + "." + Chr(10) + "~ q.e.d. ~"
ProcedureReturn lorem$
EndProcedure
If OpenWindow(0, 0, 0, 310, 240, "#LOREM$ your own", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EditorGadget(0, 10, 10, 290, 190 ,#PB_Editor_WordWrap)
TextGadget(3, 30, 210, 80, 22, "characters:")
StringGadget(2, 100, 210, 50, 22, "400")
ButtonGadget(1, 160, 210, 120, 22, "create lorem")
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
gtk_text_view_set_wrap_mode_(GadgetID(0), #GTK_WRAP_WORD)
CompilerEndIf
Repeat
wwe = WaitWindowEvent()
Select wwe
Case #PB_Event_Gadget
Select EventGadget()
Case 1
SetGadgetText(0, Lorem(Val(GetGadgetText(2))))
EndSelect
EndSelect
Until wwe = #PB_Event_CloseWindow
EndIf
Two growing code-collections: WinApi-Lib by RSBasic ~ LinuxAPI-Lib by Omi
Missing a download-file on the forums? ~ check out this backup page.
Missing a download-file on the forums? ~ check out this backup page.
-
- User
- Posts: 49
- Joined: Wed Dec 17, 2014 11:54 am
Re: Constant request: #LOREM$
The idea was to have a longish block of text always available for testing with examples, and implemented as a single constant that could be used. Rolling your own defeats this purpose. There are so many example codes in this forum that show how to do things (capitalize each word, pluck a word from inside a string, how to do word wrap) but each example includes a block of text made up with var$=var+whatever$ to make the example work. To me, a #LOREM$ constant with an always-available and reliable string of text, makes it easier to code such examples. That's all I'm asking. Just a request. Didn't mean to start a debate of why it's bad or why it sucks or why it's stupid.
Re: Constant request: #LOREM$
Hello, PB Fanatic. And welcome to the PureBasic forum.PB Fanatic wrote:...Just a request. Didn't mean to start a debate of why it's bad or why it sucks or why it's stupid.
In all honesty, the discussion only hovers on feasibility, and not functionality. Granted, there are merits to the request, and if the development team concurs, you'll have yourself a new feature.
In the time being, we're a very friendly bunch. Really!
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel
Re: Constant request: #LOREM$
Take it lighthearted PB Fanatic
Rarely a request gets so much creative attention and you surely have been heard.
~ have g d days ahead ~
Rarely a request gets so much creative attention and you surely have been heard.
~ have g d days ahead ~
Two growing code-collections: WinApi-Lib by RSBasic ~ LinuxAPI-Lib by Omi
Missing a download-file on the forums? ~ check out this backup page.
Missing a download-file on the forums? ~ check out this backup page.
- Joakim Christiansen
- Addict
- Posts: 2452
- Joined: Wed Dec 22, 2004 4:12 pm
- Location: Norway
- Contact:
Re: Constant request: #LOREM$
Agreed! Simple things like this could be added "immediately" without taking time from the bigger projects, so I don't agree with netmaestro on this. I say just add it, taking time to think too much about it takes more time than adding it. And no it doesn't cause much bloat to the compiler, it's a 64 bit world today and the compiler is still less than 1 MB (we can handle it)...Tenaja wrote:I cannot imagine the implementation taking any longer than a copy/paste, perhaps two or three additional keystrokes... if it takes longer than that, then he has set up constants with a convoluted implementation.netmaestro wrote:Does it make sense? Sure it does. Will it happen within 7 years? No, too many other things have priority. When the dev team has the time to add stuff like this to the language, we really will have arrived. Reclining on the beach, sipping margaritas and watching Apple Microsoft and Symantec straining to catch up. PureOS is on 78% of devices, Fred has just bought Hawaii and anyone with a PB license can vacation as Fantaisie's guest anytime. Ahh...to get a large block of random text (for testing) makes absolute perfect sense
I like logic, hence I dislike humans but love computers.
-
- User
- Posts: 49
- Joined: Wed Dec 17, 2014 11:54 am
Re: Constant request: #LOREM$
Are you serious? A mere 445 characters, less than half a kilobyte, is considered bloat? If this feature ever makes it into the compiler, then you better start saving for a bigger hard drive right now, my friend.heartbone wrote:Imbedding test data into the compiler is IMO bloat.
-
- User
- Posts: 49
- Joined: Wed Dec 17, 2014 11:54 am
Re: Constant request: #LOREM$
Now Vera, wouldn't you have much preferred to just have posted this:Vera wrote:... you can try my "#LOREM$ your own"Code: Select all
Procedure.s Lorem(length.i) For i = 1 To length If an = 0 ; grant capital letter at startup & new sentence x = Random(25) + 65 : an = 1 Else x = Random(24) + 97 EndIf If ch <> 0 ; prevent startup/sentence with space (resp. dot) a = Random(4) b = Random(3) If a = b Or ch > 9 ; create words by chance or if getting too long x = 32 : ch = 0 EndIf EndIf If z = x :x + 1 ; prevent double-letters by moving x by one position ElseIf z = 33 : x = 46 ; create sentence if space (32+1) occured twice in a row lorem$ = lorem$ + Chr(x) + Chr(32) : ch = -1 : an = 0 lorem$ = ReplaceString(lorem$, " .", ".") ; remove prior space & possible double-dots lorem$ = ReplaceString(lorem$, "..", ".") Else lorem$ = lorem$ + Chr(x) EndIf ch + 1 ; count 'word-letters' z = x ; set z to prevent double-letters Next lorem$ = RTrim(lorem$, " ") ; clean up possible text-ending and apply s.th. defined lorem$ = RTrim(lorem$, ".") lorem$ = lorem$ + "." + Chr(10) + "~ q.e.d. ~" ProcedureReturn lorem$ EndProcedure If OpenWindow(0, 0, 0, 310, 240, "#LOREM$ your own", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) EditorGadget(0, 10, 10, 290, 190 ,#PB_Editor_WordWrap) TextGadget(3, 30, 210, 80, 22, "characters:") StringGadget(2, 100, 210, 50, 22, "400") ButtonGadget(1, 160, 210, 120, 22, "create lorem") CompilerIf #PB_Compiler_OS = #PB_OS_Linux gtk_text_view_set_wrap_mode_(GadgetID(0), #GTK_WRAP_WORD) CompilerEndIf Repeat wwe = WaitWindowEvent() Select wwe Case #PB_Event_Gadget Select EventGadget() Case 1 SetGadgetText(0, Lorem(Val(GetGadgetText(2)))) EndSelect EndSelect Until wwe = #PB_Event_CloseWindow EndIf
Code: Select all
If OpenWindow(0, 0, 0, 310, 240, "#LOREM$ your own", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EditorGadget(0, 10, 10, 290, 190 ,#PB_Editor_WordWrap)
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
gtk_text_view_set_wrap_mode_(GadgetID(0), #GTK_WRAP_WORD)
CompilerEndIf
Repeat
wwe = WaitWindowEvent()
Select wwe
Case #PB_Event_Gadget
Select EventGadget()
Case 1
SetGadgetText(0, #LOREM$)
EndSelect
EndSelect
Until wwe = #PB_Event_CloseWindow
EndIf
Re: Constant request: #LOREM$
I'm not sure ... I don't think the outcome would be half as thrilling as minePB Fanatic wrote:Now Vera, wouldn't you have much preferred to just have posted this: [...]
Indeed, I got that.That's what my request is all about: reducing the need to build a big string for testing.
... and I'm fine if it'll come one day
Two growing code-collections: WinApi-Lib by RSBasic ~ LinuxAPI-Lib by Omi
Missing a download-file on the forums? ~ check out this backup page.
Missing a download-file on the forums? ~ check out this backup page.
Re: Constant request: #LOREM$
It is also possible to do this:
As an example they create these types of strings (respectively):
# a $3. R<c; < #[Q+)> 0 a^* p+ j < 1g < > `tN?%2::
k?1o 1LF i tU4rWXK L uW9 IX7aY36 EYMFKZc1U s aWeom64 6KzI1FI 7YB
p7'rIwiIG<@v3?Yu:<P4OK*bpup9iCf&1N*J.C#Y)*;x*,wC]s&XWhfPqs>H-:(A
It would also be possible to use RandomData and Base64Encode but you would need to allocate some extra memory for the base64 encoding.
Personally I like RandomText3(), it provides Ascii 32 to Ascii 122 range. I did not test if RandomText3() or RandomText1() performs best though.
RandomText1() will look better on a forum (more possibilities of word-wrapping due to the larger number of spaces).
Code: Select all
Procedure.s RandomText1(length.l)
Protected *mem, i.i, *text.Ascii, text$
*mem = AllocateMemory(length, #PB_Memory_NoClear)
RandomData(*mem, length)
*text = *mem
For i = 1 To length
If *text\a > 122
*text\a = *text\a & $3F
EndIf
If *text\a < 33
*text\a = *text\a & $E0
EndIf
If *text\a = 0
*text\a = 32
EndIf
*text + 1
Next
text$ = PeekS(*mem, length, #PB_Ascii)
ProcedureReturn text$
EndProcedure
Debug RandomText1(64)
Code: Select all
Procedure.s RandomText2(length.l)
Protected *mem, i.i, *text.Byte, text$
Protected Dim chars.b(63), c.b
For c = 48 To 57
chars(i) = c
i + 1
Next
For c = 63 To 90
chars(i) = c
i + 1
Next
For c = 97 To 122
chars(i) = c
i + 1
Next
*mem = AllocateMemory(length, #PB_Memory_NoClear)
RandomData(*mem, length)
*text = *mem
For i = 1 To length
If (*text\b & $8) And (i & $1)
*text\b = 32
Else
*text\b = chars(*text\b & $3F)
EndIF
*text + 1
Next
text$ = PeekS(*mem, length, #PB_Ascii)
ProcedureReturn text$
EndProcedure
Debug RandomText2(64)
Code: Select all
Procedure.s RandomText3(length.l)
Protected *mem, i.i, *text.Byte, text$
*mem = AllocateMemory(length, #PB_Memory_NoClear)
*text = *mem
For i = 1 To length
*text\b = Random(90) + 32
*text + 1
Next
text$ = PeekS(*mem, length, #PB_Ascii)
ProcedureReturn text$
EndProcedure
# a $3. R<c; < #[Q+)> 0 a^* p+ j < 1g < > `tN?%2::
k?1o 1LF i tU4rWXK L uW9 IX7aY36 EYMFKZc1U s aWeom64 6KzI1FI 7YB
p7'rIwiIG<@v3?Yu:<P4OK*bpup9iCf&1N*J.C#Y)*;x*,wC]s&XWhfPqs>H-:(A
It would also be possible to use RandomData and Base64Encode but you would need to allocate some extra memory for the base64 encoding.
Personally I like RandomText3(), it provides Ascii 32 to Ascii 122 range. I did not test if RandomText3() or RandomText1() performs best though.
RandomText1() will look better on a forum (more possibilities of word-wrapping due to the larger number of spaces).