<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Malloc]]></title><description><![CDATA[Blog on  Embedded | IOT | VLSI | DSP | LINUX PRG |ROBOTICS]]></description><link>https://malloc.engineersnation.com</link><generator>RSS for Node</generator><lastBuildDate>Fri, 10 Apr 2026 09:00:39 GMT</lastBuildDate><atom:link href="https://malloc.engineersnation.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[CrystalLang-Blocks]]></title><description><![CDATA[A block is the same thing as a method, but it does not belong to an object. Blocks are called closures in other programming languages. There are some important points about Blocks in crystal: 
    Block can accept arguments and returns a value.  
   ...]]></description><link>https://malloc.engineersnation.com/crystallang-blocks</link><guid isPermaLink="true">https://malloc.engineersnation.com/crystallang-blocks</guid><category><![CDATA[crystal]]></category><category><![CDATA[Crystal language]]></category><dc:creator><![CDATA[EngineersNation]]></dc:creator><pubDate>Sat, 27 Jan 2024 00:59:26 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1706317080570/d0c99c4a-42f2-4878-bec0-011e56c25f86.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>A block is the same thing as a method, but it does not belong to an object. Blocks are called closures in other programming languages. There are some important points about Blocks in crystal: </p>
<p>    Block can accept arguments and returns a value.  </p>
<p>    Block does not have their own name.</p>
<p>    Block consist of chunks of code. </p>
<p>    A block is always invoked with a function or can say passed to a method call.</p>
<p>    To call a block within a method with a value, yield statement is used. </p>
<p>    Blocks can be called just like methods from inside the method that it is passed to</p>
<h4 id="heading-inside-the-doend-statement-syntax">Inside the do..end statement Syntax:</h4>
<pre><code># crystal program to demonstrate the block
# defined inside <span class="hljs-keyword">do</span>..end statements

# here <span class="hljs-string">'each'</span> is the method name 
# or block name 
# n is the variable
[<span class="hljs-string">"Geeks"</span>, <span class="hljs-string">"GFG"</span>, <span class="hljs-number">55</span>].each <span class="hljs-keyword">do</span> |n| 
puts n 
end
</code></pre><p> output</p>
<p> Geeks</p>
<p>GFG   </p>
<p>55   </p>
<h4 id="heading-inline-between-the-curly-braces-syntax">Inline between the curly braces {} Syntax:</h4>
<pre><code># crystal program to demonstrate the block
# Inline between the curly braces {}

# here <span class="hljs-string">'each'</span> is the method name 
# n is the variable
[<span class="hljs-string">"Geeks"</span>, <span class="hljs-string">"GFG"</span>, <span class="hljs-number">55</span>].each {|i| puts i}
</code></pre><p>output</p>
<p> Geeks   </p>
<p>GFG</p>
<p>55</p>
<h4 id="heading-block-arguments-arguments-can-be-passed-to-block-by-enclosing-between-the-pipes-or-vertical-bars">Block Arguments: Arguments can be passed to block by enclosing between the pipes or vertical bars( | | ).</h4>
<pre><code># crystal program to demonstrate the 
# <span class="hljs-built_in">arguments</span> passing to block

# here india_states is an array and 
# it is the argument which is to 
# be passed to block 
india_states = [<span class="hljs-string">"Andhra Pradesh"</span>, <span class="hljs-string">"Assam"</span>, <span class="hljs-string">"Bihar"</span>, <span class="hljs-string">"Chhattisgarh"</span>, 
                <span class="hljs-string">"Goa"</span>, <span class="hljs-string">"Gujarat"</span>, <span class="hljs-string">"Haryana"</span>, <span class="hljs-string">"Arunachal Pradesh"</span>,
                <span class="hljs-string">"Karnataka"</span>, <span class="hljs-string">"Manipur"</span>, <span class="hljs-string">"Punjab"</span>, <span class="hljs-string">"Uttar Pradesh"</span>, 
                <span class="hljs-string">"Uttarakhand"</span>] 

# passing argument to block
india_states.each <span class="hljs-keyword">do</span> |india_states|
puts india_states
end
</code></pre><p>Output</p>
<p>Andhra Pradesh
Assam
Bihar
Chhattisgarh
Goa
Gujarat
Haryana
Arunachal Pradesh
Karnataka
Manipur
Punjab
Uttar Pradesh
Uttarakhand</p>
<p>Explanation: In above example, india_states is the argument which is passed to the block. Here it is similar to def method_name (india_states). The only difference is that method has a name but not block and arguments passed between brackets () to method but in block, arguments passed between pipes ||. 
How block return values: Actually block returns the value which are returned by the method on which it is called. </p>
<pre><code># crystal program to demonstrate how block returns the values

# here two methods called i.e <span class="hljs-string">'select'</span> and <span class="hljs-string">'even?'</span>
# even? method is called inside the block
puts [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>].select { |num| num.even? }
</code></pre><p>Output  </p>
<p>[2, 4]</p>
<p>Explanation: In above example, there are two methods i.e. select , even? and a block. At first, the select method will call the block for each number in the array. First, it will pass the 11 to block, and now inside the block, there is another method named even? which will take it as num variable and return false for 11. This false value will be passed to the select method which will discard it and then it will pass 12 to the block and similarly inside the block, odd? method is called which return true for the 12 and this true value will be passed to select method. Now select method will store this value. Similarly for remaining values in array select method will store the values in the array and at last final array will return to puts method which prints returned array elements on the screen. </p>
<h4 id="heading-the-yield-statement">The yield Statement</h4>
<p>The yield statement is used to call a block inside the method using the yield keyword with a value. </p>
<pre><code>
# crystal program to demonstrate the <span class="hljs-keyword">yield</span> statement

# method
def shivi

# statement <span class="hljs-keyword">of</span> the method to be executed
puts <span class="hljs-string">"Inside Method!"</span>

    # using <span class="hljs-keyword">yield</span> statement
    <span class="hljs-keyword">yield</span>

# statement <span class="hljs-keyword">of</span> the method to be executed 
puts <span class="hljs-string">"Again Inside Method!"</span>

# using <span class="hljs-keyword">yield</span> statement
<span class="hljs-keyword">yield</span>

end

# block
shivi{puts <span class="hljs-string">"Inside Block!"</span>}
</code></pre><p>Output</p>
<p>Inside Method!  </p>
<p>Inside Block!</p>
<p>Again Inside Method!   </p>
<p>Inside Block!</p>
<p>Explanation: In above program, method name is shivi. At first method statements is called which display Inside Method. But as soon as yield statements execute the control goes to block and block will execute its statements. As soon as the block will execute it gives control back to the method and the method will continue to execute from where yield statement called. </p>
<p>Note: Parameters can be passed to the yield statement.    </p>
<pre><code>
# crystal program to demonstrate the <span class="hljs-keyword">yield</span> statement

# method
def shivi

# statement <span class="hljs-keyword">of</span> the method to be executed
puts <span class="hljs-string">"Inside Method!"</span>

    # using <span class="hljs-keyword">yield</span> statement
    # p1 is the parameter
    <span class="hljs-keyword">yield</span> <span class="hljs-string">"p1"</span>

# statement <span class="hljs-keyword">of</span> the method to be executed 
puts <span class="hljs-string">"Again Inside Method!"</span>

# using <span class="hljs-keyword">yield</span> statement
# p2 is the parameter
<span class="hljs-keyword">yield</span> <span class="hljs-string">"p2"</span> 

end

# block
shivi{ |para| puts <span class="hljs-string">"Inside Block #{para}"</span>}
</code></pre><p>Output  </p>
<p>Inside Method!</p>
<p>Inside Block p1</p>
<p>Again Inside Method!</p>
<p>Inside Block p2</p>
<p><strong>BEGIN and END Block</strong>: crystal source file has a feature to declare the block of code which can run as the file is being loaded i.e the BEGIN block. After the complete execution of the program END block will execute. A program can contain more than 1 BEGIN and END block. BEGIN blocks will always execute in a order but END blocks will execute in reverse order. </p>
<pre><code>
# crystal program to demonstrate the use <span class="hljs-keyword">of</span> 
# same variable outside and inside a block

#!<span class="hljs-regexp">/usr/</span>bin/crystal

# variable <span class="hljs-string">'x'</span> outside the block 
x = <span class="hljs-string">"Outside the block"</span>

# here x is inside the block
<span class="hljs-number">4.</span>times <span class="hljs-keyword">do</span> |x| 
puts <span class="hljs-string">"Value Inside the block: #{x}"</span> 
end

puts <span class="hljs-string">"Value Outside the block: #{x}"</span>
</code></pre><p>Output  </p>
<p>Value Inside the block: 0</p>
<p>Value Inside the block: 1 </p>
<p>Value Inside the block: 2</p>
<p>Value Inside the block: 3</p>
<p>Value Outside the block: Outside the block</p>
<p>ref:https://www.geeksforgeeks.org/ruby-blocks/</p>
<p>code is tested on:https://play.crystal-lang.org/</p>
]]></content:encoded></item><item><title><![CDATA[CrystalLang-Initialize Method]]></title><description><![CDATA[The initialize method is useful when we want to initialize some class variables at the time of object creation. The initialize method is part of the object-creation process in Crystal and it allows us to set the initial values for an object.
Below ar...]]></description><link>https://malloc.engineersnation.com/crystallang-initialize-method</link><guid isPermaLink="true">https://malloc.engineersnation.com/crystallang-initialize-method</guid><category><![CDATA[crystal]]></category><category><![CDATA[Crystal language]]></category><dc:creator><![CDATA[EngineersNation]]></dc:creator><pubDate>Sat, 13 Jan 2024 10:00:11 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1705139938587/dc3cf9fe-3502-4dbd-869b-1c6465eec3e0.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>The initialize method is useful when we want to initialize some class variables at the time of object creation. The initialize method is part of the object-creation process in Crystal and it allows us to set the initial values for an object.</p>
<p>Below are some points about Initialize :</p>
<p>    We can define default argument.</p>
<p>    It will always return a new object so return keyword is not used inside initialize method.    </p>
<p>    Defining initialize keyword is not necessary if our class doesn’t require any arguments.   </p>
<p>    If we try to pass arguments into new and if we don’t define initialize we are going to get an error. </p>
<pre><code><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Rectangle</span> 
  @<span class="hljs-title">x</span> </span>= Int32
  @y = Int32

# Method <span class="hljs-keyword">with</span> initialize keyword 
def initialize(x : Int32 , <span class="hljs-attr">y</span> : Int32) 

    # Initialize variable 
    @x = x 
    @y = y 
end
  def display_details() 
    puts <span class="hljs-string">"value of x: #{@x}"</span>
    puts <span class="hljs-string">"value of y: #{@y}"</span>

   end
end

# create a <span class="hljs-keyword">new</span> Rectangle instance by calling 
r1 = Rectangle.new(<span class="hljs-number">10</span>, <span class="hljs-number">20</span>) 
r1.display_details
</code></pre><p>output      </p>
<p>value of x: 10       </p>
<p>value of y: 20</p>
<p>Ref: https://www.geeksforgeeks.org/the-initialize-method-in-ruby/</p>
<p>Code is tested at :https://play.crystal-lang.org/#/r/gc3o</p>
]]></content:encoded></item><item><title><![CDATA[CrystalLang-Regex01]]></title><description><![CDATA[A regular expression is a sequence of characters that define a search pattern, mainly for use in pattern matching with strings. Ruby regular expressions i.e. Crysal regex for short, helps us to find particular patterns inside a string. Two uses of Cr...]]></description><link>https://malloc.engineersnation.com/crystallang-regex01</link><guid isPermaLink="true">https://malloc.engineersnation.com/crystallang-regex01</guid><category><![CDATA[crystal]]></category><category><![CDATA[Crystal language]]></category><dc:creator><![CDATA[EngineersNation]]></dc:creator><pubDate>Mon, 08 Jan 2024 09:06:07 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1704704693358/8550b9c7-c606-4c08-bfd1-619d5e7eae53.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>A regular expression is a sequence of characters that define a search pattern, mainly for use in pattern matching with strings. Ruby regular expressions i.e. Crysal regex for short, helps us to find particular patterns inside a string. Two uses of Crysal regex are Validation and Parsing. Crysal regex can be used to validate an email address and an IP address too. Crysal regex expressions are declared between two forward slashes.</p>
<p>Syntax:</p>
<pre><code># finding the word <span class="hljs-string">'hi'</span>
<span class="hljs-string">"Hi there, i am using gfg"</span> =~ <span class="hljs-regexp">/hi/</span>
</code></pre><p>This will return the index of first occurrence of the word ‘hi’ if present, or else will return ‘ nil ‘.
Checking if a string has a regex or not</p>
<p>We can also check if a string has a regex or not by using the match method. Below is the example to understand.</p>
<pre><code># Crysal program <span class="hljs-keyword">of</span> regular expression 

# Checking <span class="hljs-keyword">if</span> the word is present <span class="hljs-keyword">in</span> the string 
<span class="hljs-keyword">if</span> <span class="hljs-string">"hi there"</span>.match(<span class="hljs-regexp">/hi/</span>) 
    puts <span class="hljs-string">"match"</span>
end
</code></pre><p>Output:</p>
<p>match</p>
<p>Checking if a string has some set of characters or not</p>
<p>We can use a character class which lets us define a range of characters for the match. For example, if we want to search for vowel, we can use [aeiou] for match.</p>
<pre><code># Crysal program <span class="hljs-keyword">of</span> regular expression 

# declaring a <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">which</span> <span class="hljs-title">checks</span> <span class="hljs-title">for</span> <span class="hljs-title">vowel</span> <span class="hljs-title">in</span> <span class="hljs-title">a</span> <span class="hljs-title">string</span> 
<span class="hljs-title">def</span> <span class="hljs-title">contains_vowel</span>(<span class="hljs-params">str</span>) 
<span class="hljs-title">str</span> =~ /[<span class="hljs-title">aeiou</span>]/ 
<span class="hljs-title">end</span>

# <span class="hljs-title">Driver</span> <span class="hljs-title">code</span> 

# <span class="hljs-title">Geeks</span> <span class="hljs-title">has</span> <span class="hljs-title">vowel</span> <span class="hljs-title">at</span> <span class="hljs-title">index</span> 1, <span class="hljs-title">so</span> <span class="hljs-title">function</span> <span class="hljs-title">returns</span> 1 
<span class="hljs-title">puts</span>(<span class="hljs-params"> contains_vowel(<span class="hljs-string">"Geeks"</span>) </span>) 

# <span class="hljs-title">bcd</span> <span class="hljs-title">has</span> <span class="hljs-title">no</span> <span class="hljs-title">vowel</span>, <span class="hljs-title">so</span> <span class="hljs-title">return</span> <span class="hljs-title">nil</span> <span class="hljs-title">and</span> <span class="hljs-title">nothing</span> <span class="hljs-title">is</span> <span class="hljs-title">printed</span> 
<span class="hljs-title">puts</span>(<span class="hljs-params"> contains_vowel(<span class="hljs-string">"bcd"</span>) </span>)</span>
</code></pre><p>Output:</p>
<p>1</p>
<p>There are different short expressions for specifying character ranges :</p>
<p>    \w is equivalent to [0-9a-zA-Z<em>]
    \d is the same as [0-9]
    \s matches white space
    \W anything that’s not in [0-9a-zA-Z</em>]
    \D anything that’s not a number
    \S anything that’s not a space
    The dot character . matches all but does not match new line. If you want to search . character, then you have to escape it.</p>
<pre><code># Crysal program <span class="hljs-keyword">of</span> regular expression 

a=<span class="hljs-string">"2m3"</span>
b=<span class="hljs-string">"2.5"</span>
# . literal matches <span class="hljs-keyword">for</span> all character 
<span class="hljs-keyword">if</span>(a.match(<span class="hljs-regexp">/\d.\d/</span>)) 
    puts(<span class="hljs-string">"match found"</span>) 
<span class="hljs-keyword">else</span>
    puts(<span class="hljs-string">"not found"</span>) 
end
# after escaping it, it matches <span class="hljs-keyword">with</span> only <span class="hljs-string">'.'</span> literal 
<span class="hljs-keyword">if</span>(a.match(<span class="hljs-regexp">/\d\.\d/</span>)) 
    puts(<span class="hljs-string">"match found"</span>) 
<span class="hljs-keyword">else</span>
    puts(<span class="hljs-string">"not found"</span>) 
end

<span class="hljs-keyword">if</span>(b.match(<span class="hljs-regexp">/\d.\d/</span>)) 
    puts(<span class="hljs-string">"match found"</span>) 
<span class="hljs-keyword">else</span>
    puts(<span class="hljs-string">"not found"</span>) 
end
</code></pre><p>Output:</p>
<p>match found
not found
match found</p>
<p>or matching multiple characters we can use modifiers:</p>
<ul>
<li>is for 1 or more characters</li>
<li>is for 0 or more characters
? is for 0 or 1 character
{x, y} if for number of characters between x and y
i is for ignores case when matching text.
x is for ignores white space and allows comments in regular expressions.
m is for matches multiple lines, recognizing newlines as normal characters.
u,e,s,n are for interprets the regexp as Unicode (UTF-8), EUC, SJIS, or ASCII. the regular expression is assumed to use the source encoding, If none of these modifiers is specified.</li>
</ul>
<p>source : https://www.geeksforgeeks.org/ruby-regular-expressions/?ref=lbp</p>
<p>code is tested on:https://play.crystal-lang.org/</p>
]]></content:encoded></item><item><title><![CDATA[CrystalLang-Iterators]]></title><description><![CDATA[The word iterate means doing one thing multiple times and that is what iterators do. Sometimes iterators are termed as the custom loops. 
    “Iterators” is the object-oriented concept in crystal.
    In more simple words, iterators are the methods w...]]></description><link>https://malloc.engineersnation.com/crystallang-iterators</link><guid isPermaLink="true">https://malloc.engineersnation.com/crystallang-iterators</guid><category><![CDATA[crystal]]></category><category><![CDATA[Crystal language]]></category><category><![CDATA[crystals]]></category><dc:creator><![CDATA[EngineersNation]]></dc:creator><pubDate>Thu, 04 Jan 2024 10:09:04 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1704362868823/dd191e6b-bf90-46fc-90a8-17ad53c31473.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>The word iterate means doing one thing multiple times and that is what iterators do. Sometimes iterators are termed as the custom loops. </p>
<p>    “Iterators” is the object-oriented concept in crystal.
    In more simple words, iterators are the methods which are supported by collections(Arrays, Hashes etc.). Collections are the objects which store a group of data members.
    crystal iterators return all the elements of a collection one after another.
    crystal iterators are “chainable” i.e adding functionality on top of each other.
There are many iterators in crystal as follows: 
Each Iterator: This iterator returns all the elements of an array or a hash. Each iterator returns each value one by one.   </p>
<pre><code>collection.each <span class="hljs-keyword">do</span> |variable_name|
   # code to be iterate
end
</code></pre><pre><code># crystal program to illustrate each iterator

#!<span class="hljs-regexp">/usr/</span>bin/crystal 

# using each iterator
# here collection is range
# variable name is i
(<span class="hljs-number">0.</span><span class="hljs-number">.9</span>).each <span class="hljs-keyword">do</span> |i|

    # statement to be executed
    puts i

end

a = [<span class="hljs-string">'G'</span>, <span class="hljs-string">'e'</span>, <span class="hljs-string">'e'</span>, <span class="hljs-string">'k'</span>, <span class="hljs-string">'s'</span>]

puts <span class="hljs-string">"\n"</span>

# using each iterator
# here collection is an array
a.each <span class="hljs-keyword">do</span>|arr|

    # statement to be executed
    puts arr

end
</code></pre><p>    Output: </p>
<p>0
1
2
3
4
5
6
7
8
9</p>
<p>G
e
e
k
s  </p>
<p>    Times Iterator: In this iterator, a loop is implanted with the specific number of time. The loop is initially started from zero and runs until the one less than the specified number.
    This can be used with no iteration variable.. We can add an iteration variable by using the vertical bars around the identifier. 
    Syntax:</p>
<pre><code>t.times <span class="hljs-keyword">do</span> |variable_name|

# code to be execute

end
</code></pre><p>    Here t is the specified number which is used to define the number of iteration.</p>
<pre><code># crystal program to illustrate time iterator

#!<span class="hljs-regexp">/usr/</span>bin/crystal

# using times iterator by providing 
# <span class="hljs-number">7</span> <span class="hljs-keyword">as</span> the iterate value
<span class="hljs-number">7.</span>times <span class="hljs-keyword">do</span> |i|
    puts i
end
</code></pre><p>    Output: </p>
<p>0
1
2
3
4
5
6   </p>
<p>    Upto Iterator: This iterator follows top to bottom approach. It includes both the top and bottom variable in the iteration. 
    Syntax: </p>
<pre><code>top.upto(bottom) <span class="hljs-keyword">do</span> |variable_name|

# code to execute

end
</code></pre><p>    Here iteration starts from top and ends on bottom. The important point to remember that the value of bottom variable is always greater than the top variable and if it is not, then it will return nothing.   </p>
<pre><code>    # crystal program to illustrate the upto iterator

#!<span class="hljs-regexp">/usr/</span>bin/crystal

# using upto iterator
# here top value is <span class="hljs-number">4</span>
# bottom value is <span class="hljs-number">7</span>
<span class="hljs-number">4.</span>upto(<span class="hljs-number">7</span>) <span class="hljs-keyword">do</span> |n| 
puts n 
end

# here top &gt; bottom
# so no output
<span class="hljs-number">7.</span>upto(<span class="hljs-number">4</span>) <span class="hljs-keyword">do</span> |n| 
puts n 
end
</code></pre><p>    Output: </p>
<p>4
5
6
7</p>
<p>    Downto Iterator: This iterator follows bottom to top approach. It includes both the top and bottom variable in the iteration. 
    Syntax: </p>
<pre><code>top.downto(bottom) <span class="hljs-keyword">do</span> |variable_name|

# code to execute

end
</code></pre><p>    Here iteration starts from bottom and ends on top. The important point to remember that the value of bottom variable is always smaller than the top variable and if it is not, then it will return nothing.    </p>
<pre><code>    # crystal program to illustrate the downto iterator

#!<span class="hljs-regexp">/usr/</span>bin/crystal

# using downto iterator
# here top value is <span class="hljs-number">7</span>
# bottom value is <span class="hljs-number">4</span>
<span class="hljs-number">7.</span>downto(<span class="hljs-number">4</span>) <span class="hljs-keyword">do</span> |n| 
puts n 
end

# here top &lt; bottom
# so no output
<span class="hljs-number">4.</span>downto(<span class="hljs-number">7</span>) <span class="hljs-keyword">do</span> |n| 
puts n 
end
</code></pre><p>    Output: </p>
<p>7
6
5
4  </p>
<p>    Step Iterator: crystal step iterator is used to iterate where the user has to skip a specified range.    </p>
<p>    Syntax:   </p>
<pre><code>Collection.step(rng) <span class="hljs-keyword">do</span> |variable_name|

#code to be executed

end
</code></pre><p>    Here rng is the range which will be skipped throughout the iterate operation.     </p>
<p>   <code>` </code>     </p>
<pre><code>    #crystal program to illustrate step iterator

#!<span class="hljs-regexp">/usr/</span>bin/crystal

#using step iterator
#skipping value is <span class="hljs-number">10</span>
#(<span class="hljs-number">0.</span><span class="hljs-number">.60</span> ) is the range
(<span class="hljs-number">0.</span><span class="hljs-number">.60</span>).step(<span class="hljs-number">10</span>) <span class="hljs-keyword">do</span>|i|
    puts i
end
</code></pre><p>    Output: </p>
<p>0
10
20
30
40
50
60</p>
<p>    Each_line Iterator: crystal each_line iterator is used to iterate over a new line in the string.    </p>
<p>    Syntax:  </p>
<pre><code>   string.each_line <span class="hljs-keyword">do</span> |variable_name|

#code to be executed

end
</code></pre><pre><code>#crystal program to illustrate Each_line iterator

#!<span class="hljs-regexp">/usr/</span>bin/crystal

#using each_line iterator
<span class="hljs-string">"Welcome\nto\nGeeksForGeeks\nPortal"</span>.each_line <span class="hljs-keyword">do</span>|i|
puts i
end
</code></pre><p>    Output: </p>
<p>Welcome
to
GeeksForGeeks
Portal      </p>
<p>source:- geeksforgeeks.org</p>
<p>all code is tested on : https://play.crystal-lang.org/</p>
]]></content:encoded></item><item><title><![CDATA[CrystalLang-Static  Members]]></title><description><![CDATA[In crystal lang, static members are known as class variables. These variables are shared among all instances of a class and are declared using the @@ symbol. Class variables retain their value across different instances of the class and can be access...]]></description><link>https://malloc.engineersnation.com/crystallang-static-members</link><guid isPermaLink="true">https://malloc.engineersnation.com/crystallang-static-members</guid><category><![CDATA[crystal]]></category><category><![CDATA[Crystal language]]></category><dc:creator><![CDATA[EngineersNation]]></dc:creator><pubDate>Thu, 28 Dec 2023 07:42:09 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1703749276338/83dea26a-5020-4949-9681-fc57e22f5281.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In crystal lang, static members are known as class variables. These variables are shared among all instances of a class and are declared using the @@ symbol. Class variables retain their value across different instances of the class and can be accessed using the class name. This allows them to serve as static members, providing shared data or functionality across instances.</p>
<p>Here is a brief overview of static members in crystal lang:  </p>
<p>    Declaration: Class variables are declared using the @@ symbol.   </p>
<p>    Scope: They are shared across all instances of the class.    </p>
<p>    Access: Class variables can be accessed using the class name followed by @@ and the variable name.    </p>
<p>    Initialization: Class variables can be initialized within the class definition.    </p>
<pre><code>    <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Example</span>    

  @@<span class="hljs-title">static_variable</span> </span>= <span class="hljs-number">10</span>

  def print_static_variable
    puts @@static_variable
  end
end
</code></pre><p>In this example,  @@ static_variable is a class variable shared among all instances of the Example class.</p>
<p>In Programming, static keywords are primarily used for memory management. The static keyword is used to share the same method or variable of a class across the objects of that class. There are various members of a class in crystal lang. Once an object is created in crystal lang, the methods and variables for that object are within the object of that class. Methods may be public, private, or protected, but there is no concept of a static method or variable in crystal lang. crystal lang doesn’t have a static keyword that denotes that a particular method belongs to the class level. However static variable can be implemented in crystal lang using class variable and a static method can be implemented in crystal lang using a class variable in one of the methods of that class. In crystal lang, there are two implementations for the static keyword: Static Variable: A Class can have variables that are common to all instances of the class. Such variables are called static variables. A static variable is implemented in crystal lang using a class variable. When a variable is declared as static, space for it gets allocated for the lifetime of the program. The name of the class variable always begins with the @@ symbol.    </p>
<pre><code># crystal lang program to demonstrate Static Variable

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Geeks</span>

    # <span class="hljs-title">class</span> <span class="hljs-title">variable</span>
    @@<span class="hljs-title">geek_count</span> </span>= <span class="hljs-number">0</span>

    def initialize
        @@geek_count += <span class="hljs-number">1</span>
        puts <span class="hljs-string">"Number of Geeks = #{@@geek_count}"</span>
    end
end

# creating objects <span class="hljs-keyword">of</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Geeks</span> 
<span class="hljs-title">g1</span> </span>= Geeks.new
g2 = Geeks.new
g3 = Geeks.new
g4 = Geeks.new
</code></pre><p>Output  </p>
<p>Number of Geeks = 1   </p>
<p>Number of Geeks = 2    </p>
<p>Number of Geeks = 3   </p>
<p>Number of Geeks = 4    </p>
<p>In the above program, the Geeks class has a class variable geek_count. This geek_count variable can be shared among all the objects of class Geeks. the static variables are shared by the objects Static Method: A Class can have a method that is common to all instances of the class. Such methods are called static methods.Static methods can be implemented in crystal lang using class variables in the methods of that class.</p>
<pre><code># crystal lang program to demonstrate Static Method

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Geeks</span>

    #<span class="hljs-title">class</span> <span class="hljs-title">method</span>
    @@<span class="hljs-title">geek_count</span> </span>= <span class="hljs-number">0</span>

    # defining instance method 
    def incrementGeek
        @@geek_count += <span class="hljs-number">1</span>
    end
    # defining <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">method</span>
    <span class="hljs-title">def</span> <span class="hljs-title">self</span>.<span class="hljs-title">getCount</span>
        <span class="hljs-title">return</span> @@<span class="hljs-title">geek_count</span>
    <span class="hljs-title">end</span>
<span class="hljs-title">end</span>

# <span class="hljs-title">creating</span> <span class="hljs-title">objects</span> <span class="hljs-title">of</span> <span class="hljs-title">class</span> <span class="hljs-title">Geeks</span>
<span class="hljs-title">g1</span> </span>= Geeks.new
# calling instance method
g1.incrementGeek()

g2 = Geeks.new
# calling instance method
g2.incrementGeek()

g3 = Geeks.new
# calling instance method
g3.incrementGeek()

g4 = Geeks.new
# calling instance method
g4.incrementGeek()

# calling <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">method</span>
<span class="hljs-title">puts</span> "<span class="hljs-title">Total</span> <span class="hljs-title">Number</span> <span class="hljs-title">of</span> <span class="hljs-title">Geeks</span> </span>= #{Geeks.getCount()}<span class="hljs-string">"</span>
</code></pre><p>Output</p>
<p>Total Number of Geeks = 4</p>
<p>In the above program, incrementGeek() the getCount() method is the static (class) method of the class Geeks which can be shared among all the objects of class Geeks. Static member functions are allowed to access only the static data members or other static member functions, they can not access the non-static data members or member functions.</p>
<p>source : geeksforgeeks    </p>
<p>code is tested on:https://play.crystal-lang.org/</p>
]]></content:encoded></item><item><title><![CDATA[CrystalLang-Inheritance]]></title><description><![CDATA[crystal is the ideal object-oriented language. In an object-oriented programming language, inheritance is one of the most important features. Inheritance allows the programmer to inherit the characteristics of one class into another class. crystal su...]]></description><link>https://malloc.engineersnation.com/crystallang-inheritance</link><guid isPermaLink="true">https://malloc.engineersnation.com/crystallang-inheritance</guid><category><![CDATA[crystal]]></category><category><![CDATA[Crystal language]]></category><dc:creator><![CDATA[EngineersNation]]></dc:creator><pubDate>Wed, 27 Dec 2023 08:54:19 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1703667155762/398cdd86-fac6-4103-bafe-5a7df2c32cab.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>crystal is the ideal object-oriented language. In an object-oriented programming language, inheritance is one of the most important features. Inheritance allows the programmer to inherit the characteristics of one class into another class. crystal supports only single class inheritance, it does not support multiple class inheritance but it supports mixins. The mixins are designed to implement multiple inheritances in crystal, but it only inherits the interface part. </p>
<p>Inheritance provides the concept of “reusability”, i.e. If a programmer wants to create a new class and there is a class that already includes some of the code that the programmer wants, then he or she can derive a new class from the existing class. By doing this, it increases the reuse of the fields and methods of the existing class without creating extra code.
Key terms in Inheritance: </p>
<p>    <strong>Super class</strong>: The class whose characteristics are inherited is known as a superclass or base class or parent class.</p>
<p>    <strong>Sub class</strong>: The class which is derived from another class is known as a subclass or derived class or child class. You can also add its own objects, methods in addition to base class methods and objects, etc.
Syntax:  </p>
<p><code>subclass_name &lt; superclass_name</code>   </p>
<pre><code># crystal program to demonstrate 
# the Inheritance

#!<span class="hljs-regexp">/usr/</span>bin/crystal 

# Super <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">or</span> <span class="hljs-title">parent</span> <span class="hljs-title">class</span>
<span class="hljs-title">class</span> <span class="hljs-title">GeekNation</span> 

    # <span class="hljs-title">constructor</span> <span class="hljs-title">of</span> <span class="hljs-title">super</span> <span class="hljs-title">class</span>
    <span class="hljs-title">def</span> <span class="hljs-title">initialize</span> 

        <span class="hljs-title">puts</span> "<span class="hljs-title">This</span> <span class="hljs-title">is</span> <span class="hljs-title">Superclass</span>"
    <span class="hljs-title">end</span>

    # <span class="hljs-title">method</span> <span class="hljs-title">of</span> <span class="hljs-title">the</span> <span class="hljs-title">superclass</span>
    <span class="hljs-title">def</span> <span class="hljs-title">super_method</span>

        <span class="hljs-title">puts</span> "<span class="hljs-title">Method</span> <span class="hljs-title">of</span> <span class="hljs-title">superclass</span>"
    <span class="hljs-title">end</span>
<span class="hljs-title">end</span>

# <span class="hljs-title">subclass</span> <span class="hljs-title">or</span> <span class="hljs-title">derived</span> <span class="hljs-title">class</span> 
<span class="hljs-title">class</span> <span class="hljs-title">Sudo_Placement</span> &lt; <span class="hljs-title">GeekNation</span> 

    # <span class="hljs-title">constructor</span> <span class="hljs-title">of</span> <span class="hljs-title">deriver</span> <span class="hljs-title">class</span>
    <span class="hljs-title">def</span> <span class="hljs-title">initialize</span> 

    <span class="hljs-title">puts</span> "<span class="hljs-title">This</span> <span class="hljs-title">is</span> <span class="hljs-title">Subclass</span>"
    <span class="hljs-title">end</span>
<span class="hljs-title">end</span>

# <span class="hljs-title">creating</span> <span class="hljs-title">object</span> <span class="hljs-title">of</span> <span class="hljs-title">superclass</span>
<span class="hljs-title">GeekNation</span>.<span class="hljs-title">new</span>

# <span class="hljs-title">creating</span> <span class="hljs-title">object</span> <span class="hljs-title">of</span> <span class="hljs-title">subclass</span>
<span class="hljs-title">sub_obj</span> </span>= Sudo_Placement.new

# calling the method <span class="hljs-keyword">of</span> <span class="hljs-built_in">super</span> 
# <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">using</span> <span class="hljs-title">sub</span> <span class="hljs-title">class</span> <span class="hljs-title">object</span>
<span class="hljs-title">sub_obj</span>.<span class="hljs-title">super_method</span></span>
</code></pre><p>output:</p>
<p>This is Superclass   </p>
<p>This is Subclass     </p>
<p>Method of superclass     </p>
<p>Overriding of Parent or Superclass method: Method overriding is a very effective feature of crystal. In method overriding, subclass and superclass contain the same method’s name, but performing different tasks or we can say that one method overrides another method. If superclass contains a method and subclass also contain the same method name then subclass method will get execute   </p>
<pre><code># crystal program to demonstrate 
# Overriding <span class="hljs-keyword">of</span> Parent or 
# Superclass method 

#!<span class="hljs-regexp">/usr/</span>bin/crystal

# parent <span class="hljs-class"><span class="hljs-keyword">class</span>
<span class="hljs-title">class</span> <span class="hljs-title">Geeks</span>

    # <span class="hljs-title">method</span> <span class="hljs-title">of</span> <span class="hljs-title">the</span> <span class="hljs-title">superclass</span> 
    <span class="hljs-title">def</span> <span class="hljs-title">super_method</span>

        <span class="hljs-title">puts</span> "<span class="hljs-title">This</span> <span class="hljs-title">is</span> <span class="hljs-title">Superclass</span> <span class="hljs-title">Method</span>"
<span class="hljs-title">end</span>

<span class="hljs-title">end</span>

# <span class="hljs-title">derived</span> <span class="hljs-title">class</span> '<span class="hljs-title">crystal</span>' 
<span class="hljs-title">class</span> <span class="hljs-title">crystal</span> &lt; <span class="hljs-title">Geeks</span> 

    # <span class="hljs-title">overriding</span> <span class="hljs-title">the</span> <span class="hljs-title">method</span> <span class="hljs-title">of</span> <span class="hljs-title">the</span> <span class="hljs-title">superclass</span> 
    <span class="hljs-title">def</span> <span class="hljs-title">super_method</span>

        <span class="hljs-title">puts</span> "<span class="hljs-title">Override</span> <span class="hljs-title">by</span> <span class="hljs-title">Subclass</span>"
<span class="hljs-title">end</span>
<span class="hljs-title">end</span>

# <span class="hljs-title">creating</span> <span class="hljs-title">object</span> <span class="hljs-title">of</span> <span class="hljs-title">sub</span> <span class="hljs-title">class</span>
<span class="hljs-title">obj</span> </span>= crystal.new

# calling the method
obj.super_method
</code></pre><p>output:    </p>
<p>Override by Subclass    </p>
<p>Use of super Method in Inheritance: This method is used to call the parent class method in the child class. If the method does not contain any argument it automatically passes all its arguments. A super method is defined by super keyword. Whenever you want to call parent class method of the same name so you can simply write super or super().  </p>
<pre><code># crystal Program to demonstrate the 
# use <span class="hljs-keyword">of</span> <span class="hljs-built_in">super</span> method

#!<span class="hljs-regexp">/usr/</span>bin/crystal

# base <span class="hljs-class"><span class="hljs-keyword">class</span>
<span class="hljs-title">class</span> <span class="hljs-title">Geeks_1</span>

    # <span class="hljs-title">method</span> <span class="hljs-title">of</span> <span class="hljs-title">superclass</span> <span class="hljs-title">accepting</span> 
    # <span class="hljs-title">two</span> <span class="hljs-title">parameter</span>
  <span class="hljs-title">def</span> <span class="hljs-title">display</span> (<span class="hljs-title">a</span> </span>= <span class="hljs-number">0</span>, b = <span class="hljs-number">0</span>)
        puts <span class="hljs-string">"Parent class, 1st Argument: #{a}, 2nd Argument: #{b}"</span>
    end
end

# derived <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Geeks_2</span>
<span class="hljs-title">class</span> <span class="hljs-title">Geeks_2</span> &lt; <span class="hljs-title">Geeks_1</span>

    # <span class="hljs-title">subclass</span> <span class="hljs-title">method</span> <span class="hljs-title">having</span> <span class="hljs-title">the</span> <span class="hljs-title">same</span> <span class="hljs-title">name</span>
    # <span class="hljs-title">as</span> <span class="hljs-title">superclass</span>
  <span class="hljs-title">def</span> <span class="hljs-title">display</span> (<span class="hljs-title">a</span>, <span class="hljs-title">b</span>)

        # <span class="hljs-title">calling</span> <span class="hljs-title">the</span> <span class="hljs-title">superclass</span> <span class="hljs-title">method</span>
        # <span class="hljs-title">by</span> <span class="hljs-title">default</span> <span class="hljs-title">it</span> <span class="hljs-title">will</span> <span class="hljs-title">pass</span> 
        # <span class="hljs-title">both</span> <span class="hljs-title">the</span> <span class="hljs-title">arguments</span>
        <span class="hljs-title">super</span>

        # <span class="hljs-title">passing</span> <span class="hljs-title">only</span> <span class="hljs-title">one</span> <span class="hljs-title">argument</span>
        <span class="hljs-title">super</span> <span class="hljs-title">a</span>

        # <span class="hljs-title">passing</span> <span class="hljs-title">both</span> <span class="hljs-title">the</span> <span class="hljs-title">argument</span>
        <span class="hljs-title">super</span> <span class="hljs-title">a</span>, <span class="hljs-title">b</span>

        # <span class="hljs-title">calling</span> <span class="hljs-title">the</span> <span class="hljs-title">superclass</span> <span class="hljs-title">method</span>
        # <span class="hljs-title">by</span> <span class="hljs-title">default</span> <span class="hljs-title">it</span> <span class="hljs-title">will</span> <span class="hljs-title">not</span> <span class="hljs-title">pass</span> 
        # <span class="hljs-title">both</span> <span class="hljs-title">the</span> <span class="hljs-title">arguments</span>
        <span class="hljs-title">super</span>()

        <span class="hljs-title">puts</span> "<span class="hljs-title">Hey</span>! <span class="hljs-title">This</span> <span class="hljs-title">is</span> <span class="hljs-title">subclass</span> <span class="hljs-title">method</span>"
    <span class="hljs-title">end</span>
<span class="hljs-title">end</span>

# <span class="hljs-title">creating</span> <span class="hljs-title">object</span> <span class="hljs-title">of</span> <span class="hljs-title">derived</span> <span class="hljs-title">class</span> 
<span class="hljs-title">obj</span> </span>= Geeks_2.new

# calling the method <span class="hljs-keyword">of</span> subclass
obj.display <span class="hljs-string">"Sudo_Placement"</span>, <span class="hljs-string">"GFG"</span>
</code></pre><p>output:   </p>
<p>Parent class, 1st Argument: Sudo_Placement, 2nd Argument: GFG   </p>
<p>Parent class, 1st Argument: Sudo_Placement, 2nd Argument: 0    </p>
<p>Parent class, 1st Argument: Sudo_Placement, 2nd Argument: GFG    </p>
<p>Parent class, 1st Argument: 0, 2nd Argument: 0    </p>
<p>Hey! This is subclass method</p>
<p>source: geeksforgeeks </p>
<p>code is tested on:     </p>
<p>https://play.crystal-lang.org/#/cr</p>
]]></content:encoded></item><item><title><![CDATA[CrystalLang-Lambda]]></title><description><![CDATA[In CrystalLang, a lambda is a type of anonymous function or a block of code that can be assigned to a variable or used inline. It encapsulates control flow, parameters, and local variables into a single package.       
lambda_variable = ->(param) { p...]]></description><link>https://malloc.engineersnation.com/crystallang-lambda</link><guid isPermaLink="true">https://malloc.engineersnation.com/crystallang-lambda</guid><category><![CDATA[crystal]]></category><category><![CDATA[Crystal language]]></category><dc:creator><![CDATA[EngineersNation]]></dc:creator><pubDate>Tue, 26 Dec 2023 06:32:16 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1703572258716/5937b89f-d6e8-49c8-b1d2-5cfa66f8837f.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In CrystalLang, a lambda is a type of anonymous function or a block of code that can be assigned to a variable or used inline. It encapsulates control flow, parameters, and local variables into a single package.       </p>
<p><code>lambda_variable = -&gt;(param) { puts param }</code></p>
<p>Anonymous Functions: Lambdas are also known as anonymous functions, as they don't have a name and can be treated as objects.</p>
<p>Usage Similar to Procs: In CrystalLang, lambdas are similar to procs but with a key distinction. Lambdas require a specific number of arguments, ensuring they are called with the correct number.</p>
<p>Objects in CrystalLang: Lambdas are treated as objects in CrystalLang, allowing them to be assigned to variables and passed around like other objects.    </p>
<p>In CrystalLang, lambdas are anonymous function code blocks that can take zero or more arguments. They can then be stored or passed in other values and called primarily with the #call method.
<code>-&gt;</code> (stabby lambda)
lambdas allow you to store functions inside a variable and call the method from other parts of a program.  </p>
<pre><code>my_lambda = -&gt; { puts <span class="hljs-string">"hello"</span> }

my_lambda.call
</code></pre><p>Output  </p>
<p>hello</p>
<pre><code>lambda = -&gt;(name : <span class="hljs-built_in">String</span>) { puts <span class="hljs-string">"Hello #{name}"</span> }

lambda.call(<span class="hljs-string">"geeknation"</span>)
</code></pre><p>Output  </p>
<p>Hello geeknation</p>
<pre><code>myLambda = -&gt; (v : Int32) { v * <span class="hljs-number">2</span> }



puts myLambda.call(<span class="hljs-number">2</span>)    
<span class="hljs-string">`</span>
</code></pre><p> Output:<br /> 4   </p>
<pre><code>
full_name = -&gt; (first : <span class="hljs-built_in">String</span>, <span class="hljs-attr">last</span>: <span class="hljs-built_in">String</span>) { first + <span class="hljs-string">" "</span> + last } 
puts full_name.call(<span class="hljs-string">"geek"</span>, <span class="hljs-string">"nation"</span>)
</code></pre><p>output   </p>
<p>geek nation</p>
<p>Lambda for Return behavior</p>
<p> In the case of the lambda,when it comes to returning values from methods, it processed the remaining part of the method.</p>
<pre><code>def my_method 

  x_lambda = -&gt;  {<span class="hljs-keyword">return</span>} 

  x_lambda.call 

  p <span class="hljs-string">"code within the method"</span> 

end 



my_method
</code></pre><p>Output  </p>
<p>"code within the method"</p>
<p>Lambda while Argument count</p>
<p>lambdas count the arguments you pass to them:   </p>
<pre><code>full_name = -&gt; (first : <span class="hljs-built_in">String</span>, <span class="hljs-attr">last</span>: <span class="hljs-built_in">String</span>) { first + <span class="hljs-string">" "</span> + last } 

puts full_name.call(<span class="hljs-string">"geek"</span>, <span class="hljs-string">"nation"</span>, <span class="hljs-string">"dev"</span>)
</code></pre><p>output  </p>
<p>error</p>
<p>code is tested on:<br />https://play.crystal-lang.org/#/cr</p>
]]></content:encoded></item><item><title><![CDATA[CrystalLang-Methods]]></title><description><![CDATA[In CrystalLang, a method is a collection of statements that performs a specific task and returns a result. Methods are crucial for code organization and re usability, bundling one or more repeatable statements into a cohesive unit. Invoking a method ...]]></description><link>https://malloc.engineersnation.com/crystallang-methods</link><guid isPermaLink="true">https://malloc.engineersnation.com/crystallang-methods</guid><category><![CDATA[crystal]]></category><category><![CDATA[Crystal language]]></category><dc:creator><![CDATA[EngineersNation]]></dc:creator><pubDate>Mon, 25 Dec 2023 07:51:05 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1703490592414/649c3c3f-5aac-4cc1-adfc-5b5e72fca9ea.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In CrystalLang, a method is a collection of statements that performs a specific task and returns a result. Methods are crucial for code organization and re usability, bundling one or more repeatable statements into a cohesive unit. Invoking a method in CrystalLang is done using dot notation.
Key points about CrystalLang methods:</p>
<p>    Definition: Methods are defined using the def keyword, followed by the method name and its parameters.</p>
<p>    Functionality: They encapsulate a set of expressions that execute a particular operation.</p>
<p>    Reusability: Methods enhance code modularity and reusability by allowing the same set of instructions to be executed multiple times.</p>
<p>    Syntax: Method calls in CrystalLang involve invoking the method on an object using dot notation.
    Understanding methods is fundamental to effective CrystalLang programming, contributing to code clarity and maintainability.   </p>
<pre><code>    <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Sports</span>
  # <span class="hljs-title">Class</span> <span class="hljs-title">method</span> 

  <span class="hljs-title">def</span> <span class="hljs-title">self</span>.<span class="hljs-title">match_start</span>

    <span class="hljs-title">puts</span> "<span class="hljs-title">match</span> <span class="hljs-title">start</span>"
  <span class="hljs-title">end</span> 

  # <span class="hljs-title">Instance</span> <span class="hljs-title">method</span> 

  <span class="hljs-title">def</span> <span class="hljs-title">practice</span>

    <span class="hljs-title">puts</span> "<span class="hljs-title">Practice</span> <span class="hljs-title">hard</span>"
  <span class="hljs-title">end</span>    
<span class="hljs-title">end</span> 

<span class="hljs-title">Sports</span>.<span class="hljs-title">match_start</span>

<span class="hljs-title">s</span> </span>= Sports.new

s.practice
</code></pre><p>Output    </p>
<p>match start   </p>
<p>Practice hard</p>
<p>  a class method can be called in conjunction with the name of the class, whereas the instance method requires you to create an instance to call the method.</p>
<p>  why you need an instance method at all when it's so much easier to call a class method.</p>
<p>  imagine that you have 3 methods in your class
  suppose you have to call a method 3 times, so there are two ways:-
 either call method via class
 or 
 call method via instance variable
 lets take first    </p>
<pre><code>  <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Sports</span> 
  # 3 <span class="hljs-title">methods</span> <span class="hljs-title">inside</span> 
<span class="hljs-title">end</span> 

<span class="hljs-title">Sports</span>.<span class="hljs-title">method_1</span> 
<span class="hljs-title">Sports</span>.<span class="hljs-title">method_2</span> 
<span class="hljs-title">Sports</span>.<span class="hljs-title">method_3</span></span>
</code></pre><p>Calling the class every time doesn't look good and is considered to be bad programming practice. Essentially, this is creating 3 new objects in the program.</p>
<p>Creating an instance variable and calling all the methods with it is a better practice:</p>
<pre><code><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Sports</span> 
  # 3 <span class="hljs-title">methods</span> <span class="hljs-title">inside</span> 
<span class="hljs-title">end</span> 

<span class="hljs-title">i</span> </span>= Sports.new 
i.method_1 
i.method_2 
i.method_3
</code></pre><p>This way you're not creating a new instance of the class every time, instead you're using the same instance for all methods.</p>
<p>code is tested on :https://play.crystal-lang.org/#/cr</p>
]]></content:encoded></item><item><title><![CDATA[CrystalLang-Polymorphism]]></title><description><![CDATA[In Crystal, one does not have anything like the variable types as there is in other programming languages. Every variable is an “object” which can be individually modified. One can easily add methods and functions on every object. So here, the Object...]]></description><link>https://malloc.engineersnation.com/crystallang-polymorphism</link><guid isPermaLink="true">https://malloc.engineersnation.com/crystallang-polymorphism</guid><category><![CDATA[crystal]]></category><category><![CDATA[Crystal language]]></category><dc:creator><![CDATA[EngineersNation]]></dc:creator><pubDate>Sun, 24 Dec 2023 04:42:15 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1703392864183/3df8ba23-704c-4e9e-9df8-ed3a4c115f12.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In Crystal, one does not have anything like the variable types as there is in other programming languages. Every variable is an “object” which can be individually modified. One can easily add methods and functions on every object. So here, the Object Oriented Programming plays a major role. There are many pillars of Object Oriented Programming in every other programming language, like Inheritance, Encapsulation etc. One of these pillars is Polymorphism.</p>
<p>Polymorphism is a made up of two words Poly which means Many and Morph which means Forms. So Polymorphism is a method where one is able to execute the same method using different objects. In polymorphism, we can obtain different results using the same function by passing different input objects. One can also write the If-Else commands but that just makes the code more lengthy. To avoid this, the programmers came up with the concept of polymorphism.</p>
<p>In Polymorphism, classes have different functionality but they share common interference. The concept of polymorphism can be studied under few sub categories.</p>
<p>    Polymorphism using Inheritance   </p>
<p>    Polymorphism using Duck-Typing   </p>
<p>Polymorphism using inheritance    </p>
<p>Inheritance is a property where a child class inherits the properties and methods of a parent class. One can easily implement polymorphism using inheritance. It can be explained using the following example</p>
<pre><code># Crystal program <span class="hljs-keyword">of</span> Polymorphism using inheritance 
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Vehicle</span> 
    <span class="hljs-title">def</span> <span class="hljs-title">tyreType</span> 
        <span class="hljs-title">puts</span> "<span class="hljs-title">Heavy</span> <span class="hljs-title">Car</span>"
    <span class="hljs-title">end</span>
<span class="hljs-title">end</span>

# <span class="hljs-title">Using</span> <span class="hljs-title">inheritance</span> 
<span class="hljs-title">class</span> <span class="hljs-title">Car</span> &lt; <span class="hljs-title">Vehicle</span> 
    <span class="hljs-title">def</span> <span class="hljs-title">tyreType</span> 
        <span class="hljs-title">puts</span> "<span class="hljs-title">Small</span> <span class="hljs-title">Car</span>"
    <span class="hljs-title">end</span>
<span class="hljs-title">end</span>

# <span class="hljs-title">Using</span> <span class="hljs-title">inheritance</span> 
<span class="hljs-title">class</span> <span class="hljs-title">Truck</span> &lt; <span class="hljs-title">Vehicle</span> 
    <span class="hljs-title">def</span> <span class="hljs-title">tyreType</span> 
        <span class="hljs-title">puts</span> "<span class="hljs-title">Big</span> <span class="hljs-title">Car</span>"
    <span class="hljs-title">end</span>
<span class="hljs-title">end</span>

# <span class="hljs-title">Creating</span> <span class="hljs-title">object</span> 
<span class="hljs-title">vehicle</span> </span>= Vehicle.new
vehicle.tyreType() 

# Creating different object calling same <span class="hljs-function"><span class="hljs-keyword">function</span> 
<span class="hljs-title">vehicle</span> = <span class="hljs-title">Car</span>.<span class="hljs-title">new</span>
<span class="hljs-title">vehicle</span>.<span class="hljs-title">tyreType</span>(<span class="hljs-params"></span>) 

# <span class="hljs-title">Creating</span> <span class="hljs-title">different</span> <span class="hljs-title">object</span> <span class="hljs-title">calling</span> <span class="hljs-title">same</span> <span class="hljs-title">function</span> 
<span class="hljs-title">vehicle</span> = <span class="hljs-title">Truck</span>.<span class="hljs-title">new</span>
<span class="hljs-title">vehicle</span>.<span class="hljs-title">tyreType</span>(<span class="hljs-params"></span>)</span>
</code></pre><p>Output:   </p>
<p>Heavy Car    </p>
<p>Small Car     </p>
<p>Big Car    </p>
<p>The above code is a very simple way of executing basic polymorphism. Here, the tyreType method is called using different objects like Car and Truck. The Car and Truck classes both are the child classes of Vehicle. They both inherit the methods of vehicle class (primarily the tyretype method).</p>
<p>Polymorphism using Duck-Typing   </p>
<p>In Crystal, we focus on the object’s capabilities and features rather than its class. So, Duck Typing is nothing but working on the idea of what an object can do rather than what it actually is. Or, what operations could be performed on the object rather than the class of the object.
Here is a small program to represent the before mentioned process.
Example :</p>
<pre><code># Crystal program <span class="hljs-keyword">of</span> polymorphism using Duck typing 

# Creating three different classes 
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Hotel</span> 

<span class="hljs-title">def</span> <span class="hljs-title">enters</span> 
    <span class="hljs-title">puts</span> "<span class="hljs-title">A</span> <span class="hljs-title">customer</span> <span class="hljs-title">enters</span>"
<span class="hljs-title">end</span>

<span class="hljs-title">def</span> <span class="hljs-title">type</span>(<span class="hljs-title">customer</span>) 
    <span class="hljs-title">customer</span>.<span class="hljs-title">type</span> 
<span class="hljs-title">end</span>

<span class="hljs-title">def</span> <span class="hljs-title">room</span>(<span class="hljs-title">customer</span>) 
    <span class="hljs-title">customer</span>.<span class="hljs-title">room</span> 
<span class="hljs-title">end</span>

<span class="hljs-title">end</span>

# <span class="hljs-title">Creating</span> <span class="hljs-title">class</span> <span class="hljs-title">with</span> <span class="hljs-title">two</span> <span class="hljs-title">methods</span> 
<span class="hljs-title">class</span> <span class="hljs-title">Single</span> 

<span class="hljs-title">def</span> <span class="hljs-title">type</span> 
    <span class="hljs-title">puts</span> "<span class="hljs-title">Room</span> <span class="hljs-title">is</span> <span class="hljs-title">on</span> <span class="hljs-title">the</span> <span class="hljs-title">fourth</span> <span class="hljs-title">floor</span>."
<span class="hljs-title">end</span>

<span class="hljs-title">def</span> <span class="hljs-title">room</span> 
    <span class="hljs-title">puts</span> "<span class="hljs-title">Per</span> <span class="hljs-title">night</span> <span class="hljs-title">stay</span> <span class="hljs-title">is</span> 5 <span class="hljs-title">thousand</span>"
<span class="hljs-title">end</span>

<span class="hljs-title">end</span>


<span class="hljs-title">class</span> <span class="hljs-title">Couple</span> 

# <span class="hljs-title">Same</span> <span class="hljs-title">methods</span> <span class="hljs-title">as</span> <span class="hljs-title">in</span> <span class="hljs-title">class</span> <span class="hljs-title">single</span> 
<span class="hljs-title">def</span> <span class="hljs-title">type</span> 
    <span class="hljs-title">puts</span> "<span class="hljs-title">Room</span> <span class="hljs-title">is</span> <span class="hljs-title">on</span> <span class="hljs-title">the</span> <span class="hljs-title">second</span> <span class="hljs-title">floor</span>"
<span class="hljs-title">end</span>

<span class="hljs-title">def</span> <span class="hljs-title">room</span> 
    <span class="hljs-title">puts</span> "<span class="hljs-title">Per</span> <span class="hljs-title">night</span> <span class="hljs-title">stay</span> <span class="hljs-title">is</span> 8 <span class="hljs-title">thousand</span>"
<span class="hljs-title">end</span>

<span class="hljs-title">end</span>

# <span class="hljs-title">Creating</span> <span class="hljs-title">Object</span> 
# <span class="hljs-title">Performing</span> <span class="hljs-title">polymorphism</span> 
<span class="hljs-title">hotel</span></span>= Hotel.new
puts <span class="hljs-string">"This visitor is Single."</span>
customer = Single.new
hotel.type(customer) 
hotel.room(customer) 


puts <span class="hljs-string">"The visitors are a couple."</span>
customer = Couple.new
hotel.type(customer) 
hotel.room(customer)
</code></pre><p>Output :   </p>
<p>This visitor is Single.    </p>
<p>Room is on the fourth floor.    </p>
<p>Per night stay is 5 thousand    </p>
<p>The visitors are a couple.     </p>
<p>Room is on the second floor   </p>
<p>Per night stay is 8 thousand   </p>
<p>In the above example, The customer object plays a role in working with the properties of the customer such as its “type” and its “room”. This is an example of polymorphism.    </p>
<p>source: geeksforgeeks  </p>
<p>code is tested on   </p>
<p>https://play.crystal-lang.org</p>
]]></content:encoded></item><item><title><![CDATA[CrystalLang-Encapsulation]]></title><description><![CDATA[Encapsulation is defined as the wrapping up of data under a single unit. It is the mechanism that binds together code and the data it manipulates. In a different way, encapsulation is a protective shield that prevents the data from being accessed by ...]]></description><link>https://malloc.engineersnation.com/crystallang-encapsulation</link><guid isPermaLink="true">https://malloc.engineersnation.com/crystallang-encapsulation</guid><category><![CDATA[crystal]]></category><category><![CDATA[Crystal language]]></category><dc:creator><![CDATA[EngineersNation]]></dc:creator><pubDate>Sat, 23 Dec 2023 21:56:56 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1703368539791/11f6c3a5-aee8-41e4-a9ea-61336cde87d5.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Encapsulation is defined as the wrapping up of data under a single unit. It is the mechanism that binds together code and the data it manipulates. In a different way, encapsulation is a protective shield that prevents the data from being accessed by the code outside this shield.</p>
<p>    Technically in encapsulation, the variables or data of a class are hidden from any other class and can be accessed only through any member function of own class in which they are declared.
    Encapsulation can be achieved by declaring all the variables in the class as private and writing public methods in the class to set and get the values of variables. </p>
<pre><code># Crystal program to illustrate encapsulation 

    <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Demoencapsulation</span> 
    @<span class="hljs-title">id</span> : <span class="hljs-title">Int32</span>
        @<span class="hljs-title">name</span> : <span class="hljs-title">String</span>
        @<span class="hljs-title">addr</span> : <span class="hljs-title">String</span>
<span class="hljs-title">def</span> <span class="hljs-title">initialize</span>(<span class="hljs-title">id</span>, <span class="hljs-title">name</span>, <span class="hljs-title">addr</span>) 

# <span class="hljs-title">Instance</span> <span class="hljs-title">Variables</span>     
@<span class="hljs-title">id</span>  </span>= id 
@name  = name 
@addr  = addr 
end

# displaying result 
def display_details() 
    puts <span class="hljs-string">"Customer id: #{@id}"</span>
    puts <span class="hljs-string">"Customer name: #{@name}"</span>
    puts <span class="hljs-string">"Customer address: #{@addr}"</span>
end
end

# Create Objects 
cust1 = Demoencapsulation .new  <span class="hljs-number">1</span>, <span class="hljs-string">"xx"</span>, <span class="hljs-string">"xyy"</span>
cust2 = Demoencapsulation.new   <span class="hljs-number">2</span>, <span class="hljs-string">"aa"</span>, <span class="hljs-string">"aabb"</span>


# Call Methods 
cust1.display_details()
cust2.display_details()
</code></pre><p>Output   </p>
<p>Customer id: 1    </p>
<p>Customer name: xx     </p>
<p>Customer address: xyy   </p>
<p>Customer id: 2  </p>
<p>Customer name: aa    </p>
<p>Customer address: aabb        </p>
<p>Explanation: In the above program, the class Demoencapsulation encapsulate the methods of the class. You can only access these methods with the help of objects of the Demoencapsulation class i.e. cust1 and cust2.</p>
<p>Advantages of Encapsulation:</p>
<p>    Data Hiding:The user will have no idea about the inner implementation of the class. It will not be visible to the user that how the class is storing values in the variables. User only knows that we are passing the values to a setter method and variables are getting initialized with that value.
    Re usability: Encapsulation also improves the re-usability and easy to change with new requirements.
    Testing code is easy:Encapsulated code is easy to test for unit testing.</p>
<p>source :geeksforgeeks</p>
]]></content:encoded></item><item><title><![CDATA[Crystal-Lang-Mixin]]></title><description><![CDATA[When a class can inherit features from more than one parent class, the class is supposed to have multiple inheritance. But Crystal does not support multiple inheritance directly and instead uses a facility called mixin. Mixins in Crystal allows modul...]]></description><link>https://malloc.engineersnation.com/crystal-lang-mixin</link><guid isPermaLink="true">https://malloc.engineersnation.com/crystal-lang-mixin</guid><category><![CDATA[crystal]]></category><category><![CDATA[Crystal language]]></category><dc:creator><![CDATA[EngineersNation]]></dc:creator><pubDate>Fri, 22 Dec 2023 05:51:52 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1703224240132/06546fcc-9abb-4b36-8a8b-1d5591245223.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p> When a class can inherit features from more than one parent class, the class is supposed to have multiple inheritance. But Crystal does not support multiple inheritance directly and instead uses a facility called mixin. Mixins in Crystal allows modules to access instance methods of another one using include method.
Mixins provides a controlled way of adding functionality to classes. The code in the mixin starts to interact with code in the class. In Crystal, a code wrapped up in a module is called mixins that a class can include or extend. A class consist many mixins. </p>
<pre><code># Modules consist a method 
<span class="hljs-built_in">module</span> Child_1 
def a1 
puts <span class="hljs-string">"This is Child one."</span>
end
end
<span class="hljs-built_in">module</span> Child_2 
def a2 
puts <span class="hljs-string">"This is Child two."</span>
end
end
<span class="hljs-built_in">module</span> Child_3 
def a3 
puts <span class="hljs-string">"This is Child three."</span>
end
end

# Creating <span class="hljs-class"><span class="hljs-keyword">class</span> 
<span class="hljs-title">class</span> <span class="hljs-title">Parent</span> 
<span class="hljs-title">include</span> <span class="hljs-title">Child_1</span> 
<span class="hljs-title">include</span> <span class="hljs-title">Child_2</span> 
<span class="hljs-title">include</span> <span class="hljs-title">Child_3</span> 
<span class="hljs-title">def</span> <span class="hljs-title">display</span> 
<span class="hljs-title">puts</span> "<span class="hljs-title">Three</span> <span class="hljs-title">modules</span> <span class="hljs-title">have</span> <span class="hljs-title">included</span>."
<span class="hljs-title">end</span>
<span class="hljs-title">end</span>

# <span class="hljs-title">Creating</span> <span class="hljs-title">object</span> 
<span class="hljs-title">object</span> </span>= Parent.new

# Calling methods 
object.display 
object.a1 
object.a2 
object.a3
</code></pre><p>Output    </p>
<p><code>Three modules have included.</code>    </p>
<p><code>This is Child one.</code> </p>
<p><code>This is Child two.</code>  </p>
<p><code>This is Child three.</code><br />In above example, module Child_1 consist of the method a1 similarly module Child_2 and Child_3 consist of the methods a2 and a3. The class Parent includes modules Child_1, Child_2 and Child_3 . The class Parent also include a method display. As we can see that the class Parent inherits from all three modules. the class Parent shows multiple inheritance or mixin. Object can access all four methods i.e. a1,a2,a3 and display().</p>
<p>source:geeksforgeeks</p>
]]></content:encoded></item><item><title><![CDATA[Crystal-Lang-02]]></title><description><![CDATA[A constructor in Crystal is a special method of a class that automatically gets invoked whenever an instance of the class is created. It is responsible for initializing the object's state. In Crystal, the constructor method is named initialize. When ...]]></description><link>https://malloc.engineersnation.com/crystal-lang-02</link><guid isPermaLink="true">https://malloc.engineersnation.com/crystal-lang-02</guid><category><![CDATA[crystal]]></category><category><![CDATA[crystals]]></category><category><![CDATA[Crystal language]]></category><dc:creator><![CDATA[EngineersNation]]></dc:creator><pubDate>Thu, 21 Dec 2023 11:57:18 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1703152851958/4c1710e4-e6eb-45f9-8f15-2f974002856c.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>A constructor in Crystal is a special method of a class that automatically gets invoked whenever an instance of the class is created. It is responsible for initializing the object's state. In Crystal, the constructor method is named initialize. When an object is created using the new keyword, the initialize method is called, allowing us to set up the initial state of the object.</p>
<pre><code class="lang-plaintext">class MyDemo
  def initialize(parameter)
    @attribute = parameter
  end
end
# Creating an object and invoking the constructor
obj = MyDemo.new("example")
</code></pre>
<p>In this example, the initialize method sets the at attribute instance variable with the provided parameter when an object is instantiated.<br />Important points to remember about Constructors:</p>
<p>Constructors are used to initializing the instance variables.</p>
<p>In Crystal, the constructor has a different name, unlike other programming languages.</p>
<p>A constructor is defined using the initialize and def keywords. It is treated as a special method in Crystal.</p>
<p>Constructors can’t be overloaded in Crystal.</p>
<p>Constructors can’t be inherited.</p>
<p>It returns the instance of that class.</p>
<pre><code class="lang-plaintext"># constructor
def initialize()

 # instance variable @
 # class variable  @@
   @Var1 = "GeeksforGeeks"
   @Var2 = "Sudo Placement"
end

# defining method display
def display()
 puts "Value of First instance variable is: #{@Var1}"
 puts "Value of Second instance variable is : #{@Var2}"
end
end

# creating an object of Demo
obj = Demo.new()

# calling the instance methods of Demo
obj.display()
</code></pre>
<p>output:<br /><code>Value of First instance variable is: GeeksforGeeks</code></p>
<p><code>Value of Second instance variable is: Sudo Placement</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1703160014770/3433447c-9234-40bc-ad9a-778d1c5a5b0e.png" alt class="image--center mx-auto" /></p>
<p>source:geeksforgeeks</p>
]]></content:encoded></item><item><title><![CDATA[C#-Collection-02]]></title><description><![CDATA[A collection is a group of objects.The .NET frameworks provide generic classes that represent various types of collections, such as list, queue, set, map, and others. Using these classes, we can easily perform operations such as insert, update, delet...]]></description><link>https://malloc.engineersnation.com/c-collection-02</link><guid isPermaLink="true">https://malloc.engineersnation.com/c-collection-02</guid><category><![CDATA[C#]]></category><category><![CDATA[Unity Engine]]></category><dc:creator><![CDATA[EngineersNation]]></dc:creator><pubDate>Wed, 20 Dec 2023 11:01:16 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1703070011992/5debe044-e62c-4726-b6c4-37eeb5c3c08b.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>A <strong>collection</strong> is a group of objects.The .NET frameworks provide generic classes that represent various types of collections, such as list, queue, set, map, and others. Using these classes, we can easily perform operations such as insert, update, delete, sort, and search on a collection of objects.</p>
<p>not thread-safe collection</p>
<p>    The List collection   </p>
<p>    The Stack collection    </p>
<p>    The Queue collection    </p>
<p>    The LinkedList collection  </p>
<p>    The Dictionary collection   </p>
<p>    The HashSet collection</p>
<p>l thread-safe collections are reside in the System.Collections.Concurrent namespace.<br />System.Collections.Generic namespace can be broadly grouped into two categories:</p>
<p>    Mutable, which support operations for changing the content of the collection such as adding new, or removing existing elements.
    Read-only collections, which do not provide methods for changing the content of the collection.</p>
]]></content:encoded></item><item><title><![CDATA[Linux Kernel source- How to compile]]></title><description><![CDATA[To configure the Linux kernel, enter into a directory of newly unpacked set of kernel sources and configure them using the text based menuconfig configuration utility, as follows:$ make menuconfig
Building the Kernel
Building the Linux kernel is actu...]]></description><link>https://malloc.engineersnation.com/linux-kernel-source-how-to-compile</link><guid isPermaLink="true">https://malloc.engineersnation.com/linux-kernel-source-how-to-compile</guid><category><![CDATA[Linux]]></category><category><![CDATA[linux kernel]]></category><dc:creator><![CDATA[EngineersNation]]></dc:creator><pubDate>Sat, 04 Nov 2023 13:33:09 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1699104509913/7e2b6f14-b3cc-461c-95f3-5b7d9f448e38.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>To configure the Linux kernel, enter into a directory of newly unpacked set of kernel sources and configure them using the text based menuconfig configuration utility, as follows:<br /><code>$ make menuconfig</code></p>
<p><strong>Building the Kernel</strong></p>
<p>Building the Linux kernel is actually quite straightforward. You simply use the GNU make command,and the kernel Kbuild system (that is layered upon make) will make the appropriate calls to those utilities that are needed to build the entire system. A successful build can take a long time.<br /><code>$ make</code><br />The Linux kernel source has a top-level directory structure that is always similar to the following:<br /><strong>arch</strong>:-arch Architecture-specific files<br /><strong>block</strong>:- block Support for block devices such as hard disks.<br /><strong>crypto</strong>:-crypto Cryptographic library functions<br /><strong>Documentation</strong>:- Documentation supplied with the Linux kernel.<br /><strong>drivers</strong>- Device drivers<br /><strong>fs</strong>:- Implementation of every filesystem supported by the Linux kernel.<br /><strong>include</strong>:-include Header files supplied with the Linux kernel <strong>init</strong>:-init Higher-level startup code<br /><strong>ipc</strong>:-ipc The location of the implementation of various Inter-Process Communica-tion (IPC) primitives used in the Linux kernel.<br /><strong>Kernel</strong>:-kernel The higher-level core kernel functions.<br /><strong>lib</strong>:- Library routines such as CRC32 checksum calculation and various other higher-level library code<br /><strong>mm</strong>:- Memory management routines supporting the Linux implementation of virtual memory.<br /><strong>net</strong>:- Contains an implementation of each of the networking standards that are supported by the Linux kernel <strong>scripts</strong>:- Various miscellaneous scripts used to configure and build the Linux kernel. <strong>security</strong>:- Linux includes support for the SELinux (Security-Enhanced Linux) functional<br /><strong>sound</strong>:- Contains an implementation of the ALSA (Advanced Linux Sound Architecture) sound subsystem as used in recent Linux kernels.</p>
<p><strong>usr</strong>:- Various support utilities for building initial ramdisks</p>
<h4 id="heading-commands-for-compiling-linux-kernel">Commands for Compiling Linux Kernel</h4>
<pre><code class="lang-plaintext">$make menuconfig   
$make oldconfig     
$make   
$sudo apt-get install libncurses-dev flex bison openssl libssl-dev dkms libelf-dev libudev-dev libpci-dev libiberty-dev autoconf
</code></pre>
<p><strong>System.map:-</strong></p>
<p>This file will generate automatically after compilation.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699104437963/ed89c352-a4f5-4a6c-8ca0-7f2432619c75.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699104463081/ab683a9d-b376-4140-8fd5-fd9b03a7ff27.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699104495626/f90c4722-c083-4294-ac75-360f09a76aec.png" alt class="image--center mx-auto" /></p>
]]></content:encoded></item><item><title><![CDATA[Better C++-02]]></title><description><![CDATA[Parallelism:-
Most modern microprocessors consist of more than one core, each of which can operate as an individual processing unit. They can execute different parts of different programs at the same time. The features of the std.parallelism module m...]]></description><link>https://malloc.engineersnation.com/better-c-02</link><guid isPermaLink="true">https://malloc.engineersnation.com/better-c-02</guid><category><![CDATA[C++]]></category><dc:creator><![CDATA[EngineersNation]]></dc:creator><pubDate>Mon, 25 Sep 2023 14:02:27 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1695650484015/397edbcd-1a27-494a-90c6-cb180cafbf3d.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h4 id="heading-parallelism">Parallelism:-</h4>
<p>Most modern microprocessors consist of more than one core, each of which can operate as an individual processing unit. They can execute different parts of different programs at the same time. The features of the std.parallelism module make it possible for programs to take advantage of all of the cores in order to run faster.</p>
<p><strong>parallel</strong>: Accesses the elements of a range in parallel<br /><strong>task</strong>: Creates tasks that are executed in parallel.<br /><strong>map</strong>: Calls functions with the elements of an InputRange semi-eagerly in parallel.<br /><strong>amap</strong>: Calls functions with the elements of a RandomAccessRange fully-eagerly in parallel.<br /><strong>reduce</strong>: Makes calculations over the elements of a RandomAccessRange in parallel.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1696063715773/34ecc86e-8f08-4ee9-b42b-ed9caff61cb1.png" alt class="image--center mx-auto" /></p>
<pre><code class="lang-plaintext">import std.stdio;
import core.thread;

struct Player {
    int number;

    void parallel_op() {
        writefln("match %s has begun", number);

        // Wait for a while to simulate a long-lasting operation
        Thread.sleep(2.seconds);

        writefln("match %s has ended", number);
    }
}

void main() {
    auto players =  
        [ Player(1), Player(2), Player(3),Player(4) ];

    foreach (player; players) {
        player.parallel_op();
    }
}
</code></pre>
]]></content:encoded></item></channel></rss>